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

  FORUM HardWare.fr
  Programmation
  PHP

  [résolu] Problème sur formulaire, enregistrement dans BD

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[résolu] Problème sur formulaire, enregistrement dans BD

n°1697303
ossie
Posté le 05-03-2008 à 08:30:28  profilanswer
 

Salut tout le monde,
 
Pour un examen pratique je dois réaliser un site annuaire ou des clients peuvent s'inscrire et ensuite être trouvés par le biais d'un champs de recherche. Le site comporte donc une base de données.
 
Mon problème est que je n'arrive pas à mettre en place le formulaire avec l'enregistrement dans la base de données. Lorsque je vais sur le site la page d'enregistrement me donne l'erreur Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 31
 
Est-ce que quelqu'un pourrait m'aider ? Merci d'avance pour tout bon conseil
 
Voici le code du formulaire:

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.  <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
  5.  <meta name="generator" content="Adobe GoLive">
  6.  <title>Registration</title>
  7.  <link href="style.css" rel="stylesheet" type="text/css" media="all">
  8.  <csscriptdict import>
  9.   <script type="text/javascript" src="GeneratedItems/CSScriptLib.js"></script>
  10.  </csscriptdict>
  11.  <csactiondict>
  12.   <script type="text/javascript"><!--
  13. var preloadFlag = false;
  14. function preloadImages() {
  15. if (document.images) {
  16.  pre_img_Calque_1_down = newImage('images/registration_button.data_/img_Calque-1-down.gif');
  17.  preloadFlag = true;
  18. }
  19. }
  20. // --></script>
  21.  </csactiondict>
  22. </head>
  23. <body onload="preloadImages();" bgcolor="#ffffff" leftmargin="0" marginheight="0" marginwidth="0" topmargin="0">
  24.  <div align="center">
  25.   <table width="265" border="0" cellspacing="0" cellpadding="0">
  26.    <tr height="37">
  27.     <td height="37"></td>
  28.    </tr>
  29.    <tr height="52">
  30.     <td height="52"><img src="images/title_registration.jpg" alt="" height="52" width="364" border="0"></td>
  31.    </tr>
  32.   </table>
  33.   <form action="register.php" method="post" target="_self">
  34.    <table width="513" border="0" cellspacing="0" cellpadding="0">
  35.     <tr>
  36.      <td valign="top">
  37.       <table border="0" cellspacing="0" cellpadding="0">
  38.        <tr height="42">
  39.         <td align="left" valign="middle" width="124" height="42"></td>
  40.         <td align="left" valign="middle" width="30" height="42"></td>
  41.         <td align="left" valign="middle" width="359" height="42"></td>
  42.        </tr>
  43.        <tr>
  44.         <td align="left" valign="middle" width="124">
  45.          <div align="right">
  46.           <img src="images/labels/activities.gif" alt="" height="17" width="117" border="0"></div>
  47.         </td>
  48.         <td align="left" valign="middle" width="30"></td>
  49.         <td align="left" valign="middle" width="359">
  50.          <div class="textfield">
  51.           <p><input class="textfield" type="text" name="activities" size="44"></p>
  52.          </div>
  53.         </td>
  54.        </tr>
  55.       </table>
  56.       <table border="0" cellspacing="0" cellpadding="0">
  57.        <tr height="22">
  58.         <td width="113" height="22"></td>
  59.         <td width="44" height="22"></td>
  60.         <td width="276" height="22"></td>
  61.        </tr>
  62.        <tr>
  63.         <td width="113">
  64.          <div align="right">
  65.           <img src="images/labels/society.gif" alt="" height="21" width="91" border="0"></div>
  66.         </td>
  67.         <td width="44"></td>
  68.         <td class="textfield" width="276"><input class="textfield" type="text" name="society" size="43"></td>
  69.        </tr>
  70.       </table>
  71.       <table border="0" cellspacing="0" cellpadding="0">
  72.        <tr height="40">
  73.         <td width="108" height="40"></td>
  74.         <td width="27" height="40"></td>
  75.         <td width="276" height="40"></td>
  76.        </tr>
  77.        <tr>
  78.         <td width="108">
  79.          <div align="right">
  80.           <img src="images/labels/address.gif" alt="" height="17" width="99" border="0"></div>
  81.         </td>
  82.         <td width="27"></td>
  83.         <td class="textfield" width="276"><input class="textfield" type="text" name="adress1" size="44"></td>
  84.        </tr>
  85.       </table>
  86.       <table border="0" cellspacing="0" cellpadding="0">
  87.        <tr height="14">
  88.         <td width="108" height="14"></td>
  89.         <td width="53" height="14"></td>
  90.         <td width="276" height="14"></td>
  91.        </tr>
  92.        <tr>
  93.         <td width="108">
  94.          <div align="right"></div>
  95.         </td>
  96.         <td width="53"></td>
  97.         <td class="textfield" width="276"><input class="textfield" type="text" name="adress2" size="44"></td>
  98.        </tr>
  99.       </table>
  100.       <table border="0" cellspacing="0" cellpadding="0">
  101.        <tr height="36">
  102.         <td width="108" height="36"></td>
  103.         <td width="27" height="36"></td>
  104.         <td width="276" height="36"></td>
  105.        </tr>
  106.        <tr>
  107.         <td width="108">
  108.          <div align="right">
  109.           <img src="images/labels/country.gif" alt="" height="20" width="95" border="0"></div>
  110.         </td>
  111.         <td width="27"></td>
  112.         <td class="textfield" width="276"><input class="textfield" type="text" name="country" size="44"></td>
  113.        </tr>
  114.       </table>
  115.       <table border="0" cellspacing="0" cellpadding="0">
  116.        <tr height="40">
  117.         <td width="203" height="40"></td>
  118.         <td width="20" height="40"></td>
  119.         <td width="276" height="40"></td>
  120.        </tr>
  121.        <tr>
  122.         <td width="203">
  123.          <div align="right">
  124.           <img src="images/labels/email.gif" alt="" height="18" width="176" border="0"></div>
  125.         </td>
  126.         <td width="20"></td>
  127.         <td class="textfield" width="276"><input class="textfield" type="text" name="email" size="44"></td>
  128.        </tr>
  129.       </table>
  130.       <table border="0" cellspacing="0" cellpadding="0">
  131.        <tr height="47">
  132.         <td width="99" height="47"></td>
  133.         <td width="27" height="47"></td>
  134.         <td width="276" height="47"></td>
  135.        </tr>
  136.        <tr>
  137.         <td width="99">
  138.          <div align="right">
  139.           <img src="images/labels/web.gif" alt="" height="17" width="49" border="0"></div>
  140.         </td>
  141.         <td width="27"></td>
  142.         <td class="textfield" width="276"><input class="textfield" type="text" name="web" size="44"></td>
  143.        </tr>
  144.       </table>
  145.       <table border="0" cellspacing="0" cellpadding="0">
  146.        <tr height="50">
  147.         <td width="116" height="50"></td>
  148.         <td width="17" height="50"></td>
  149.         <td width="276" height="50"></td>
  150.        </tr>
  151.        <tr>
  152.         <td width="116">
  153.          <div align="right">
  154.           <img src="images/labels/password.gif" alt="" height="21" width="118" border="0"></div>
  155.         </td>
  156.         <td width="17"></td>
  157.         <td class="textfield" width="276"><input class="textfield" type="password" name="password" size="44"></td>
  158.        </tr>
  159.       </table>
  160.       <table border="0" cellspacing="0" cellpadding="0">
  161.        <tr height="37">
  162.         <td width="312" height="37"></td>
  163.         <td width="24" height="37"></td>
  164.         <td width="158" height="37"></td>
  165.        </tr>
  166.        <tr>
  167.         <td class="textfield" width="312">
  168.          <div align="right">
  169.           <input class="textfield" type="password" name="confirmation" size="44"></div>
  170.         </td>
  171.         <td width="24"></td>
  172.         <td width="158"><img src="images/labels/confirmation.gif" alt="" height="18" width="158" border="0"></td>
  173.        </tr>
  174.       </table>
  175.       <br>
  176.       <br>
  177.       <table width="512" border="0" cellspacing="0" cellpadding="0">
  178.        <tr>
  179.         <td>
  180.          <div align="center">
  181.           <a onmousedown="changeImages('img_Calque_1','images/registration_button.data_/img_Calque-1-down.gif');return true" onmouseup="changeImages('img_Calque_1','images/registration_button.data_/img_Calque-1.gif');return true" onmouseout="changeImages('img_Calque_1','images/registration_button.data_/img_Calque-1.gif');return true"><input id="img_Calque_1" type="image" src="images/registration_button.data_/img_Calque-1.gif" alt="" name="img_Calque_1" height="66" width="162" border="0" livesrc="images/registration_button.psd"></a><input type="submit" name="submitButtonName"></div>
  182.         </td>
  183.        </tr>
  184.       </table>
  185.      </td>
  186.     </tr>
  187.    </table>
  188.   </form>
  189.  </div>
  190. </body>
  191. </html>


 
 
 
Et voici le code de la page register.php

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.  <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
  5.  <meta name="generator" content="Adobe GoLive">
  6.  <title>Thank you for your registration</title>
  7. </head>
  8. <body bgcolor="#ffffff">
  9.  <?php
  10. if (empty($_post['activities']) || empty($_post['society']) || empty($_post['adress1']) ||
  11.     empty($_post['adresse2']) || empty($_post['country']) || empty($_post['email']) ||
  12.     empty($_post['web']) || empty($_post['password']))
  13. die ("ERROR : Please, fill out every field." );
  14. if (preg_match("/^[\w\.-]+@[\w\.-]+\.[a-z]{2,3}$/",
  15. $_REQUEST ['email']) ==  false)
  16. die("ERREUR : adresse email non valide." );
  17. // connection base de donnée
  18. $liendb = mysql_connect ('localhost', 'wootchs', 'HamadA');
  19. mysql_select_db ("members", $liendb);
  20. $sql = "INSERT INTO 'registred' ('activities', 'society', 'adress1', 'adress2', 'country', 'email', 'web', 'password', 'id') VALUES ($_POST['activities'], $_POST['society'], $_POST['adress1'], $_POST['adress2'], $_POST['country'], $_POST['email'], $_POST['web'], $_POST['password'], $_POST[''])";
  21. // fin requete base de donnée
  22. if ($result = mysql_query($sql) !=false)   
  23.     print("user".$_REQUEST['name']." registred." );
  24. else
  25.     print ("Error during registration." );
  26. mysql_close($liendb);
  27.  ?>
  28. </body>
  29. </html>


Message édité par ossie le 05-03-2008 à 10:20:34
mood
Publicité
Posté le 05-03-2008 à 08:30:28  profilanswer
 

n°1697306
flo850
moi je
Posté le 05-03-2008 à 08:39:39  profilanswer
 

$_POST[''] ca ne sert a rien  
remplace tous tes $POST['variable'] par  
$variable = mysql_real_escape_string( $POST['variable'] );  
 
pour  des raisons de sécurités ( présence d'un ' dans une valeur entre autres) et de lisibilité de ta requète
 
apres on devrai y voir plus clair


---------------

n°1697312
soju
One shot !
Posté le 05-03-2008 à 08:56:34  profilanswer
 

ton erreur vient du fait que php a du mal a reconnaitre les variables dans ta requête,
plutôt que te donner la soluce, voici un peu de lecture : http://fr.php.net/manual/fr/langua [...] ng.parsing
 
PS: pas très propre ni securisé ton code...

n°1697318
ossie
Posté le 05-03-2008 à 09:07:21  profilanswer
 

Merci flo pour ta réponse rapide,
 
J'ai modifié d'après ce que tu m'a dit et j'ai au passage mis la première partie en commentaires afin de voir déjà si l'enregistrement dans la base fonctionne.  
Malheureusement l'erreur est toujours pareille.
 
Est-ce possible que l'erreur se trouve déjà dans mon formulaire ? J'ai beau relire, je n'arrive pas à en trouver une...
Merci aussi à toi soju, je vais aller faire un tour sur ce site
 
Voici le code actuel de la page register.php
 
 
 

Code :
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4.  <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
  5.  <meta name="generator" content="Adobe GoLive">
  6.  <title>Thank you for your registration</title>
  7. </head>
  8. <body bgcolor="#ffffff">
  9.  <?php
  10. /*
  11. if (empty($_post['activities']) || empty($_post['society']) || empty($_post['adress1']) ||  
  12.     empty($_post['adresse2']) || empty($_post['country']) || empty($_post['email']) ||  
  13.     empty($_post['web']) || empty($_post['password']))
  14. die ("ERROR : Please, fill out every field." );
  15.  
  16.  
  17. if (preg_match("/^[\w\.-]+@[\w\.-]+\.[a-z]{2,3}$/",
  18. $_REQUEST ['email']) ==  false)
  19.  
  20. die("ERREUR : adresse email non valide." );
  21. */
  22. // connection base de donnée
  23. $liendb = mysql_connect ('localhost', 'wootchs', 'HamadA');
  24. mysql_select_db ("members", $liendb);
  25. $sql = "INSERT INTO 'registred' ('activities', 'society', 'adress1', 'adress2', 'country', 'email', 'web', 'password', 'id')
  26. VALUES (
  27. $activities = mysql_real_escape_string( $POST['activities'] );
  28. $society = mysql_real_escape_string( $POST['society'] );
  29. $adress1 = mysql_real_escape_string( $POST['adress1'] );
  30. $adress2 = mysql_real_escape_string( $POST['adress2'] );
  31. $country = mysql_real_escape_string( $POST['country'] );
  32. $email = mysql_real_escape_string( $POST['email'] );
  33. $web = mysql_real_escape_string( $POST['web'] );
  34. $password = mysql_real_escape_string( $POST['password'] );
  35. );
  36. // fin requete base de donnée
  37. if ($result = mysql_query($sql) !=false)   
  38.     print("user".$_REQUEST['name']." registred." );
  39. else
  40.     print ("Error during registration." );
  41. mysql_close($liendb);
  42.  ?>
  43. </body>
  44. </html>

n°1697336
babasss
Posté le 05-03-2008 à 09:41:06  profilanswer
 

Qu'utilises-tu comme éditeur pour taper ton code. Parce que un simple copier coller dans Notepad++ (aussi visible avec un exament visuel) t'indiques qu'il y a un sérieux problème au niveau de ta variable $sql... Jette -y un coup d'oeil et regarde également le formalisme SQL d'un INSERT INTO (nécessiter d'avoir des virgules entre les données dans le VALUES) ....


---------------
Feedback : http://forum.hardware.fr/hfr/Achat [...] 2666_1.htm
n°1697348
ossie
Posté le 05-03-2008 à 09:59:39  profilanswer
 

J'utilise Golive. Tu avais raison le problème était au niveau du INSERT INTO. J'ai ajouté des '". et maintenant ça fonctionne.
Merci pour votre aide.
 
A+, ossie

n°1697363
flo850
moi je
Posté le 05-03-2008 à 10:11:30  profilanswer
 

remplace

Code :
  1. $sql = "INSERT INTO 'registred' ('activities', 'society', 'adress1', 'adress2', 'country', 'email', 'web', 'password', 'id')
  2. VALUES (
  3. $activities = mysql_real_escape_string( $POST['activities'] );
  4. $society = mysql_real_escape_string( $POST['society'] );
  5. $adress1 = mysql_real_escape_string( $POST['adress1'] );
  6. $adress2 = mysql_real_escape_string( $POST['adress2'] );
  7. $country = mysql_real_escape_string( $POST['country'] );
  8. $email = mysql_real_escape_string( $POST['email'] );
  9. $web = mysql_real_escape_string( $POST['web'] );
  10. $password = mysql_real_escape_string( $POST['password'] );
  11.  
  12. );
 

par

 
Code :
  1. $activities = mysql_real_escape_string( $POST['activities'] );
  2. $society = mysql_real_escape_string( $POST['society'] );
  3. $adress1 = mysql_real_escape_string( $POST['adress1'] );
  4. $adress2 = mysql_real_escape_string( $POST['adress2'] );
  5. $country = mysql_real_escape_string( $POST['country'] );
  6. $email = mysql_real_escape_string( $POST['email'] );
  7. $web = mysql_real_escape_string( $POST['web'] );
  8. $password = mysql_real_escape_string( $POST['password'] );
  9.  $sql = "INSERT INTO registred (activities, society,adress1, adress2, country, email, web, password, id)
  10. VALUES (
  11. '$activities',' $society' , '$adress1',' $adress2', '$country', '$email',' $web',' $password,'')
  12. );
 

et par pitité , quand on te donnes du code, essaye de comprendre dce que ca fait, par exmeple en lisant leur doc


Message édité par flo850 le 05-03-2008 à 10:11:42

---------------


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

  [résolu] Problème sur formulaire, enregistrement dans BD

 

Sujets relatifs
[PHP-PostgreSQL] Problème d'échappement de caractèresMail html : Décallage IE => soluce et nouveau problème
probleme tri par fusion de tableauProbleme javascript en ruby
Problème d'affectation (lib - vc2005)Problème afficher/montrer DIV
Problème avec SASProblème connexion serveur sql server
Problème sauvegarde envoi de mails Lotus Notes dans macro VBAVBA Excel, problème de filtre avec valeurs décimales
Plus de sujets relatifs à : [résolu] Problème sur formulaire, enregistrement dans BD


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