1 utilisateur anonyme et 8 utilisateurs inconnus

 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[php] suite et bientot fin

n°925
fscalda
Posté le 09-01-2004 à 14:19:15  profilanswer
 

La suite de l'autre topic .
 
Voila, le probleme, c'est que dès que je mets une apostrophe ' dans un des champs du formulaire, j'ai une erreur . Je ne sais pas comment faire pour empecher ça.
 
le formulaire d'envoie  
 
 

Code :
  1. <form action="valide.php" method="post">
  2.       <table cellspacing=0 cellpadding=0 width=511 border=0>
  3.         <tbody>
  4.         <tr>
  5.           <td class=bold colspan=3><img height=16
  6.             src="Lesaboteur_com%20-%20Th%E9mes%20de%20bureau%20-%20Galerie%20photos_fichiers/t_an-12pens-demande.gif"
  7.             width=511></td>
  8.         </tr>
  9.         <tr>
  10.           <td colspan=3><img height=34
  11.             src="Lesaboteur_com%20-%20Th%E9mes%20de%20bureau%20-%20Galerie%20photos_fichiers/bloc-haut.gif"
  12.             width=511></td>
  13.         </tr>
  14.         <tr>
  15.           <td
  16.           background="Lesaboteur_com%20-%20Th%E9mes%20de%20bureau%20-%20Galerie%20photos_fichiers/pix-noir.gif"
  17.           height="100%"><img height="100%"
  18.             src="Lesaboteur_com%20-%20Th%E9mes%20de%20bureau%20-%20Galerie%20photos_fichiers/pix-noir.gif"
  19.             width=1></td>
  20.           <td width=492> <br>
  21.               <table cellspacing=0 cellpadding=0 width=492 border=0>
  22.                 <tbody>
  23.                 <tr>
  24.                   <td><font face=arial color=#000000 size=2>Nom ou pseudo :</font></td>
  25.                   <td>
  26.                     <input type="text" name="nom">
  27.                   </td>
  28.                 </tr>
  29.                 <tr>
  30.                   <td><font face=arial color=#000000 size=2>Votre Email : </font></td>
  31.                   <td>
  32.                     <input type="text" name="email">
  33.                   </td>
  34.                 </tr>
  35.                 <tr>
  36.                   <td><font face=arial color=#000000 size=2>Telephone :</font></td>
  37.                   <td>
  38.                     <input type="text" name="telephone">
  39.                   </td>
  40.                 </tr>
  41.                 <tr>
  42.                   <td><font face=arial color=#000000 size=2>Portable :</font></td>
  43.                   <td>
  44.                     <input type="text" name="portable">
  45.                   </td>
  46.                 </tr>
  47.                 <tr>
  48.                   <td><font face=arial color=#000000 size=2>Lieu :</font></td>
  49.                   <td>
  50.                     <input type="text" name="lieu">
  51.                   </td>
  52.                 </tr>
  53.                 <tr>
  54.                   <td>Pays :</td>
  55.                   <td>
  56.                     <input type="text" name="pays">
  57.                   </td>
  58.                 </tr>
  59.                 <tr>
  60.                   <td colspan="2"><br>
  61.                     <font face=arial color=#000000 size=2>Titre:</font><br>
  62.                     <input type="text" name="titre">
  63.                   </td>
  64.                 </tr>
  65.                 <tr>
  66.                   <td colspan="2"><font face=arial color=#000000 size=2>Annonce
  67.                     :</font><br>
  68.                     <textarea style="FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: arial; BACKGROUND-COLOR: #ffffff" name="message" rows=10 cols=70></textarea>
  69.                     <br>
  70.                   </td>
  71.                 </tr>
  72.                 <tr>
  73.                   <td colspan="2">
  74.                     <div align="center">
  75.                       <input type="submit" value="cliquez-ici">
  76.                     </div>
  77.                   </td>
  78.                 </tr>
  79.                 </tbody>
  80.               </table>
  81.           </td>
  82.           <td width=18
  83.           background="Lesaboteur_com%20-%20Th%E9mes%20de%20bureau%20-%20Galerie%20photos_fichiers/pix-droite.gif"
  84.           height="100%"><img height=8
  85.             src="Lesaboteur_com%20-%20Th%E9mes%20de%20bureau%20-%20Galerie%20photos_fichiers/pix-droite.gif"
  86.             width=18></td>
  87.         </tr>
  88.         <tr>
  89.           <td colspan=3><img height=36
  90.             src="Lesaboteur_com - Thémes de bureau - Galerie photos_fichiers\bloc-bas(1).gif"
  91.             width=511></td>
  92.         </tr>
  93.         </tbody>
  94.       </table>
  95.       </form>


       
 
 
la page qui recupere le code pour l'envoyer dans la base
 

Code :
  1. <?PHP
  2. // Connexion ici  
  3. $db = mysql_connect('localhost', 'root', '');
  4. mysql_select_db('annonce',$db);
  5. //variable nom email telephone portable lieu pays titre message
  6. $date = date ("Y-m-d" );
  7. $query = "INSERT INTO webmaster(date,nom, email, telephone, portable, lieu, pays, titre, message)
  8. VALUES(NOW(),'".$_POST["nom"]."','".$_POST["email"]."','".$_POST["telephone"]."','".$_POST["portable"]."','".$_POST["lieu"]."','".$_POST["pays"]."','".$_POST["titre"]."' ,'".$_POST["message"]."')";
  9. $res=mysql_query($query) or die(mysql_error());
  10. //texte de fin  
  11. //rajouter plutot un lien vers une page
  12. echo 'merci beaucoup, vos infos ont été enregistrées.';
  13. mysql_close();
  14. ?>

mood
Google
Posté le 09-01-2004 à 14:19:15  profilanswer
 

n°926
nicodache
marmotte en chocolat concept ©
Posté le 09-01-2004 à 20:37:26  profilanswer
 

pour les apostrophe, faut les protéger avec des \
 
donc ca donne un truc du genre

Citation :

qu\'elle est belle c\'te \"souris\"


---------------
modérateur inside [:nicodache] plankaivoo [:nicodache] - ici powered - Je roule en micra 1l 55cv et je t'emmerde :o
n°927
plut0nium
M3uH v2.0
Posté le 09-01-2004 à 21:09:50  profilanswer
 

nicodache a écrit :

pour les apostrophe, faut les protéger avec des \
 
donc ca donne un truc du genre

Citation :

qu\'elle est belle c\'te \"souris\"




 
wais, mais il va pas le faire à la main... [:dslam]
 
y'a unne fonction intégrée à php pour ajouter des backslash devant tous les caractères spéciaux:

addslashes(string)


 
à utiliser avant d'insérer dans la db mysql


---------------
plut0nium.
Without evil there can be no good so it must be good to be evil sometimes
n°928
KnX
To be or not to code.
Posté le 09-01-2004 à 21:32:19  profilanswer
 

et pour afficher faut stripslasher non ?

n°929
plut0nium
M3uH v2.0
Posté le 09-01-2004 à 21:45:49  profilanswer
 

KnX a écrit :

et pour afficher faut stripslasher non ?


 
oui ;)


---------------
plut0nium.
Without evil there can be no good so it must be good to be evil sometimes
n°930
Dr Lous
I see old password
Posté le 10-01-2004 à 11:23:53  profilanswer
 

:o si c pour affichage... convertir les caractere en code html :D


---------------
Oseras-tu m'affronter ?
n°1531
fscalda
Posté le 29-01-2004 à 14:42:12  profilanswer
 

désolé, j'ai utilisé addslashes, j'ose pas montré le code, mais ça fonctionne :)

mood
Google
Posté le 29-01-2004 à 14:42:12  profilanswer
 


Aller à :
Ajouter une réponse
 

Hit Parade