Précédent   Forum des professionnels en informatique > PHP > PHP & SGBD > PHP & Oracle
PHP & Oracle Forum d'entraide sur Oracle avec PHP. Avant de poster -> FAQ Oracle et Cours Oracle
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 23/03/2011, 11h35   #1
Invité de passage
 
Inscription : mai 2005
Messages : 9
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 9
Points : 2
Points : 2
Envoyer un message via MSN à tatann
Par défaut Probleme variable requete SQL Oracle PHP

Bonjour,

J'ai un formulaire formulaire.html

Code :
1
2
3
4
5
6
7
8
<html>
<form method="POST" action="add.php">
<center>
<input type="text" name="nom" size="10" value="18/03/2009" maxlength="10"><br>
<input type="submit" value="Envoyer" name="envoyer">
</center>
</form>
</html>
Mon objectif est d'envoyer la valeur date DD/MM/YYYY dans une page add.php mais je n'arrive pas peut du fait des simples quotes à mettre $nom dans ma clause where "where trunc(STA_DATE) = '$nom'" j'ai besoin des simples quotes...j'ai essayé de mettre des doubles quotes ' " $nom ' " plus d'autres tests dont je ne me souviens plus. Il faut que j'affiche le resultat de ma selection en prenant en compte ma valeur date.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
// On commence par récupérer les champs
if(isset($_POST['nom']))      $nom=$_POST['nom'];
else      $nom="";
 
// On vérifie si les champs sont vides
if(empty($nom))
    {
    echo '<font color="red">Attention, le champs <b>DATE</b> est vide !</font>';
    }
 
// Aucun champ n'est vide, on peut enregistrer dans la table
else
    {
echo "$nom";
 
 
$db = "//********************";
$c1 = oci_connect("******", "******", $db);
 
 
function select_data($conn)
{
 
$query1 = "ALTER SESSION SET NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS'";
$stid1 = oci_parse($conn, $query1);
$r1 =oci_execute($stid1, OCI_COMMIT_ON_SUCCESS);
 
 
$stmt = oci_parse($conn, "select STA_TRAIT, STA_TYPE, STA_FLAG, STA_DATE, NOM_FICHIER, LOADER, READ, DISCARDED, REJECTED, TAUX_REJET from USER.MA_TABLE where trunc(STA_DATE) = '18/03/2010' order by STA_DATE desc");
 
 
oci_execute($stmt, OCI_DEFAULT);
 
echo "<TABLE BORDER=0 BORDERCOLOR=#152B28>";
echo "<tr BGCOLOR=#96CDC5 ALIGN=CENTER><th><FONT COLOR=#152B28>Traitements</FONT></th><th><FONT COLOR=#152B28>Types</FONT></th><th><FONT COLOR=#152B28>Flags</FONT></th><th><FONT COLOR=#152B28>Dates</FONT></th><th><FONT COLOR=#152B28>Nom de fichier</FONT></th><th><FONT COLOR=#152B28>Chargements</FONT></th><th><FONT COLOR=#152B28>Lecture</FONT></th><th><FONT COLOR=#152B28>Rejets</FONT></th><th><FONT COLOR=#152B28>Erreurs</FONT></th><th><FONT COLOR=#152B28>Taux de rejet</FONT></th>";
while (oci_fetch($stmt)) {
        echo "<tr BGCOLOR=#DCF4F1 ALIGN=LEFT>";
        echo "<td><b>" . oci_result($stmt, "STA_TRAIT") ."</b></td>";
        echo "<td>" . oci_result($stmt, "STA_TYPE") ."</td>";
        echo "<td>" . oci_result($stmt, "STA_FLAG") ."</td>";
        echo "<td ALIGN=CENTER>" . oci_result($stmt, "STA_DATE") ."</td>";
        echo "<td>" . oci_result($stmt, "NOM_FICHIER") ."</td>";
        echo "<td>" . oci_result($stmt, "LOADER") ."</td>";
        echo "<td>" . oci_result($stmt, "READ") ."</td>";
        echo "<td ALIGN=CENTER>" . oci_result($stmt, "DISCARDED") ."</td>";
        echo "<td>" . oci_result($stmt, "REJECTED") ."</td>";
        echo "<td>" . oci_result($stmt, "TAUX_REJET") ."</td>";
        echo "</tr>";
}
echo "</TABLE>";
 
}
 
select_data($c1);
 
}
 
 
?>
Merci pour votre aide...
Si vous pensez qu'il existe une méthode plus simple, je suis preneur...

A+ Stéphane
tatann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/03/2011, 11h52   #2
Modérateur
 
Avatar de Golgotha
 
Homme cédric
Développeur informatique
Inscription : août 2007
Messages : 732
Détails du profil
Informations personnelles :
Nom : Homme cédric
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : août 2007
Messages : 732
Points : 1 573
Points : 1 573
Envoyer un message via Skype™ à Golgotha
Bonjour,

Je sais pas si j'ai bien compris mais tu devrais pouvoir le faire comme ça :

Code :
"where trunc(STA_DATE) = '".$nom."'[....]
Ta variable doit juste être entouré de point pour la concaténation.
__________________
modérateur webmasters - développements web & php
faq jQuery - règles du forum - faqs web
mon espace perso
Venez participez au deuxième defi Web !
Golgotha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/03/2011, 14h12   #3
Invité de passage
 
Inscription : mai 2005
Messages : 9
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 9
Points : 2
Points : 2
Envoyer un message via MSN à tatann
Par défaut RE

Merci pour la réponse mais ca ne m affiche rien en fait sur la page...

Je remets le bout de code au cas ou j'aurai fait une erreur de syntaxe.

Code :
$stmt = oci_parse($conn, "select STA_TRAIT, STA_TYPE, STA_FLAG, STA_DATE, NOM_FICHIER, LOADER, READ, DISCARDED, REJECTED, TAUX_REJET from USRE.TABLE where trunc(STA_DATE)  = '".$nom."'  order by STA_DATE desc");
tatann est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/03/2011, 14h30   #4
Modérateur
 
Avatar de Golgotha
 
Homme cédric
Développeur informatique
Inscription : août 2007
Messages : 732
Détails du profil
Informations personnelles :
Nom : Homme cédric
Âge : 27
Localisation : France

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : août 2007
Messages : 732
Points : 1 573
Points : 1 573
Envoyer un message via Skype™ à Golgotha
J'ai peut être fait une erreur, les doubles et simple quote sont utilisées différemment en php, essaye comme ça :

Code :
$stmt = oci_parse($conn, 'select STA_TRAIT, STA_TYPE, STA_FLAG, STA_DATE, NOM_FICHIER, LOADER, READ, DISCARDED, REJECTED, TAUX_REJET from USRE.TABLE where trunc(STA_DATE)  = \''.$nom.'\'  order by STA_DATE desc');
__________________
modérateur webmasters - développements web & php
faq jQuery - règles du forum - faqs web
mon espace perso
Venez participez au deuxième defi Web !
Golgotha est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/03/2011, 17h25   #5
Invité de passage
 
Inscription : mai 2005
Messages : 9
Détails du profil
Informations forums :
Inscription : mai 2005
Messages : 9
Points : 2
Points : 2
Envoyer un message via MSN à tatann
Par défaut RE

J'ai trouvé,

En fait, je ne faisais pas appel à ma variable dans ma fonction. du coup, ca ne pouvait pas fonctionner.
tatann est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 21h34.


 
 
 
 
Partenaires

Hébergement Web