Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2295 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  Problème d'apostrophe

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème d'apostrophe

n°1738475
fourniey
Rendre au prochain
Posté le 28-05-2008 à 19:55:48  profilanswer
 

Bonjour,
 
J'ai une liste déroulante qui me permet de faire un choix. Si celui-ci contient une apostrophe, ça ne fonctionne pas avec mon sélect SQL.
 
Au niveau de l'affichage, tout est ok avec cette ligne: $statut = htmlspecialchars(stripslashes($_GET['statut']));
 
J'utilise cette variable pour la requête SQL et ça ne fonctionne pas s'il y a une apostrophe:
 
ora_parse($cur,"SELECT * FROM FON_PHP_STATUT_VUE where STATUT='$statut' and FIN_AN_STATUT='1858-11-17' order by NOM_FAMILLE, PRENOM",$x) or die(Ora_Error($conn));
 
Merci!

mood
Publicité
Posté le 28-05-2008 à 19:55:48  profilanswer
 

n°1738478
fourniey
Rendre au prochain
Posté le 28-05-2008 à 20:17:45  profilanswer
 

J'ai essayé de mettre deux apostrophes et le résultat est ''
 
$statut contient Conseil d'administration
 
$choix = str_replace($statut, "'", "''" );

n°1738522
Profil sup​primé
Posté le 28-05-2008 à 21:56:05  answer
 

pour ce genre de question basique il est préférable de passer par la documentation officielle :
 
http://fr2.php.net/htmlspecialchars
 
qui stipule :

Citation :

Vous pouvez utiliser l'une des constantes suivantes :    ENT_COMPAT, la constante par défaut,   va convertir les guillemets doubles et ignorer les guillemets   simples; ENT_QUOTES va convertir les guillemets doubles   et les guillemets simples; ENT_NOQUOTES    va ignorer les guillemets doubles et les guillemets simples.
 


Message édité par Profil supprimé le 28-05-2008 à 21:56:54
n°1738526
fourniey
Rendre au prochain
Posté le 28-05-2008 à 22:13:28  profilanswer
 

Ce que je ne comprends pas, c'est que mon problème n'est pas nouveau!

n°1738824
NewsletTux
<Insérez ici votre vie />
Posté le 29-05-2008 à 12:53:11  profilanswer
 

la doc non plus :D


---------------
NewsletTux - outil de mailing list en PHP MySQL
n°1738853
anapajari
s/travail/glanding on hfr/gs;
Posté le 29-05-2008 à 13:37:01  profilanswer
 

ton problème se situe dans le remplacement de $statut au sein de ta requête.
Osef les stripslashes, tu utilises oracle alors a toi les joies des binds variables:

Code :
  1. $stmt = ora_parse($cur,"SELECT * FROM FON_PHP_STATUT_VUE where STATUT=:statut and FIN_AN_STATUT=:dstatut order by NOM_FAMILLE, PRENOM",$x)
  2. or die(Ora_Error($conn));
  3. oci_bind_by_name($stmt, ":statut", $statut, 32);
  4. oci_bind_by_name($stmt, ":dstatut", '1858-11-17', 32);


Tu laisses ainsi le système s'occuper tout seul des ' et des ".

 

note: pense à regler le 3eme paramètre correctement ( longueur ).


Message édité par anapajari le 29-05-2008 à 13:38:20

---------------
Software and cathedrals are much the same - first we build them, then we pray.
n°1738916
fourniey
Rendre au prochain
Posté le 29-05-2008 à 15:00:40  profilanswer
 

J'ai apporté les corrections et le tableau est vide maintenant!
 
 
 

Code :
  1. <body>
  2.  <div align="center">
  3.   <?php
  4.    $statut = htmlspecialchars(stripslashes($_GET['statut']));
  5.         $statut="Conseil d'administration";
  6.         $statut=$_GET['statut'];
  7.    $conn = Ora_Logon("php_fondation@prod", "fokilfas" ) or die(Ora_Error($conn));
  8.    $cur = ora_open($conn) or die(Ora_Error($conn));
  9.    ora_parse($cur,"SELECT distinct STATUT FROM FON_PHP_STATUT_VUE",$x) or die(Ora_Error($conn));
  10.    ora_exec($cur) or die(Ora_Error($conn));
  11.    echo '<FORM action="statut.php?" METHOD="GET">';
  12.    echo '<p align="center">Liste disponible : <select name="statut">';
  13.       while(ora_fetch_into($cur,$val)) {
  14.         ?>
  15.         //<option value="<?php echo htmlspecialchars(stripslashes($val[0])) ?>"<?php if (!(strcmp($val[0], $_GET['statut']))) {echo "selected=\"selected\"";} ?>><?php echo $val[0] ?></option>
  16.         <option value="<?php echo $val[0] ?>"<?php if (!(strcmp($val[0], $_GET['statut']))) {echo "selected=\"selected\"";} ?>><?php echo $val[0] ?></option>
  17.        
  18.         <?php 
  19.    }
  20.    echo '</select>';
  21.    echo '<INPUT TYPE="submit" VALUE="Afficher la liste"></p>';
  22.    echo '</FORM>';
  23.   ?>
  24.   <table width="800" cellpadding="10px" border="3">
  25.   <caption><h2><?php echo $statut; ?></h2></caption>
  26.      <tr><th colspan="5">Liste des personnes (en cours)</th></tr>
  27.    <tr>
  28.     <th width="30">Dossier</th>
  29.     <th width="125">Nom</th>
  30.     <th width="90">Prénom</th>
  31.     <th width="40">Début</th>
  32.     <th width="70">Poste occupé</th>
  33.    </tr>
  34.    <?php
  35.     $conn = Ora_Logon("php_fondation@prod", "mdp" ) or die(Ora_Error($conn));
  36.     $cur = ora_open($conn) or die(Ora_Error($conn));
  37.     //ora_parse($cur,"SELECT * FROM FON_PHP_STATUT_VUE where STATUT='$statut' and FIN_AN_STATUT='1858-11-17' order by NOM_FAMILLE, PRENOM",$x) or die(Ora_Error($conn));
  38. $stmt = ora_parse($cur,"SELECT * FROM FON_PHP_STATUT_VUE where STATUT=:statut and FIN_AN_STATUT=:dstatut order by NOM_FAMILLE, PRENOM",$x)
  39. or die(Ora_Error($conn));
  40. oci_bind_by_name($stmt, ":statut", $statut, 32);
  41. oci_bind_by_name($stmt, ":dstatut", '1858-11-17', 32);
  42. ora_exec($cur) or die(Ora_Error($conn));
  43.     $i_actif = 0;
  44.     while(ora_fetch_into($cur,$detail)){
  45.      $i_actif++;
  46.      echo '<tr><td>';
  47.      echo htmlspecialchars(trim($detail[0]));
  48.      echo '<td align="left">'.htmlspecialchars(trim($detail[1])).'</td>';
  49.      echo '<td align="Left">'.htmlspecialchars(trim($detail[2])).'</td>';
  50.      if(htmlspecialchars(trim($detail[6]) == "58-11-17" )) {
  51.               echo '<td align="Left">&nbsp;</td>';
  52.             } 
  53.             else {
  54.               echo '<td align="Left">'.htmlspecialchars(substr($detail[6],6,2))."-".htmlspecialchars(substr($detail[6],3,2))."-".htmlspecialchars(substr($detail[6],0,2)).'</td>';                   
  55.             }
  56.           echo '<td align="left">'.htmlspecialchars(trim($detail[8])).'</td>';                 
  57.      echo '</tr>';
  58.      } //fin while
  59.      echo '</td></tr>';
  60.             echo '<tr><td colspan="6"><b>Nombre de personnes : </b>'.$i_actif;
  61.             echo '</td></table>';
  62.      echo '<br><br>';
  63.         ?>
  64.      <table width="800" cellpadding="10px" border="3">
  65.        <tr>
  66.        <th colspan="6">Liste des personnes (mandat terminé)</th>
  67.       </tr>
  68.       <tr>
  69.        <th width="25">Dossier</th>
  70.        <th width="150">Nom</th>
  71.        <th width="90">Prénom</th>
  72.        <th width="40">Début</th>
  73.        <th width="40">Fin</th>
  74.        <th width="70">Poste occupé</th>
  75.       </tr>
  76.         <?php
  77.     $conn = Ora_Logon("php_fondation@prod", "mdp" ) or die(Ora_Error($conn));
  78.     $cur = ora_open($conn) or die(Ora_Error($conn));
  79.     ora_parse($cur,"SELECT * FROM FON_PHP_STATUT_VUE where STATUT='$statut' and FIN_AN_STATUT<>'1858-11-17' order by NOM_FAMILLE, PRENOM",$x) or die(Ora_Error($conn));
  80.     ora_exec($cur) or die(Ora_Error($conn));
  81.     $i_inactif = 0;
  82.     while(ora_fetch_into($cur,$detail)){
  83.      $i_inactif++;
  84.      echo '<tr><td>';
  85.      echo htmlspecialchars(trim($detail[0]));
  86.      echo '<td align="left">'.htmlspecialchars(trim($detail[1])).'</td>';
  87.      echo '<td align="Left">'.htmlspecialchars(trim($detail[2])).'</td>';
  88.      if(htmlspecialchars(trim($detail[6]) == "58-11-17" )) {
  89.               echo '<td align="Left">&nbsp;</td>';
  90.             } 
  91.             else {
  92.               echo '<td align="Left">'.htmlspecialchars(substr($detail[6],6,2))."-".htmlspecialchars(substr($detail[6],3,2))."-".htmlspecialchars(substr($detail[6],0,2)).'</td>';                   
  93.             }
  94.             if(htmlspecialchars(trim($detail[7]) == "58-11-17" )) {
  95.               echo '<td align="Left">&nbsp;</td>';
  96.             } 
  97.             else {
  98.              echo '<td align="Left">'.htmlspecialchars(substr($detail[7],6,2))."-".htmlspecialchars(substr($detail[7],3,2))."-".htmlspecialchars(substr($detail[7],0,2)).'</td>';                   
  99.             }             
  100.           echo '<td align="left">'.htmlspecialchars(trim($detail[8])).'</td>';                 
  101.      echo '</tr>';
  102.      } //fin while
  103.      echo '</td></tr>';
  104.             echo '<tr><td colspan="6"><b>Nombre de personnes : </b>'.$i_inactif;
  105.             echo '</table>';
  106.    ?>
  107.        
  108. </div>
  109. </body>
  110. </html>


Message édité par fourniey le 29-05-2008 à 15:01:45

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  Problème d'apostrophe

 

Sujets relatifs
Probleme d'apostrophe en javascriptprobleme d'apostrophe flash/php
Probleme d'apostrophe.Problème d'apostrophe dans un formulaire
[ASP.NET] Problème sauvegarde apostrophe dans SQL server[MySQL] problème d'apostrophe [résolu]
[XSL] Problème d'apostropheProblème d'échappement avec l'apostrophe ou '
Probleme avec l'apostrophe avec la commande mail[PHP MySQL] Problème d'apostrophe ! [MONGOLE INSIDE]
Plus de sujets relatifs à : Problème d'apostrophe


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR