Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php] b³±d z zapisaniem danych z formularza
Forum PHP.pl > Forum > Przedszkole
rts
Witam. Mia³em gotowy kod który zapisauje dane do bazy mysql.
Chcia³em do formularza dodaæ jeszcze jedno pole a poniewa¿ w ogóle siê nie znam na php ani mysql skopiowa³em linijki z kodu które zawira³y nazwy pól formularza i wstawia³em inne nazwy. Doda³em te¿ nowe pole w bazie mysql w tabeli users o tej samej nazwie co w kodzie php i warto¶ciami co inne pola w tabeli bazy.

Niestety co¶ jest nie tak poniewa¿ gdy robiê na stronie "zapisz dane" pojawia mi siê b³±d:
Cytat
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mod='', shoe=''WHERE uid='40'' at line 21
update users set password='8mvw0vv0p', first_name='', last_name='', street='', city='', state='', zip='', country='', email='', cat='', telephone='', age='', chest='', height='', weight='', waist='', eyes='', hair='', dress='', mod='', shoe=''WHERE uid='40'


Kod wygl±da tak:

  1. <?
  2. include("include/common.php");
  3.  
  4. if(!$loggedin){
  5. header("Location: login.php");
  6. }
  7. include("include/header.php");
  8. include("include/accmenu.php");
  9.  
  10. if($submit){
  11. $sql = "update users set
  12. password='$spassword',
  13. first_name='$sfirst_name',
  14. last_name='$slast_name',
  15. street='$sstreet',
  16. city='$scity',
  17. state='$sstate',
  18. zip='$szip',
  19. country='$scountry',
  20. email='$semail',
  21. cat='$scat',
  22. telephone='$stelephone',
  23. age='$sage',
  24. chest='$schest',
  25. height='$sheight',
  26. weight='$sweight',
  27. waist='$swaist',
  28. eyes='$seyes',
  29. hair='$shair',
  30. dress='$sdress',
  31. mod='$smod', <----------------------------------- doda³em tê linijkê
  32. shoe='$sshoe'WHERE uid='$myuid'";
  33.  
  34.  
  35. mysql_query($sql) or die( mysql_error()."<br>$sql" );
  36. ?>
  37. <h3>Edytuj Swoje Dane</h3>
  38. <form action=account.php method=post>
  39. <?=$table2?>
  40. <tr align=center>
  41. <td colspan=2>Dane zosta³y zapisane.</td>
  42. </tr>
  43. <?
  44. if ($cpassword != $spassword) {
  45. echo "<tr align=center><td colspan=2>Musisz siê wylogowaæ <a href=logout.php>tutaj</a> i zalogowaæ ponownie. Upewnij siê, ¿e nie masz otwartych wiêcej okien z t± s
    am± stron±.</td></tr>"
    ; 
  46. }
  47. echo "</table>";
  48. }else{
  49. $this->c=mysql_query("select * from users where uid='$myuid'");
  50. $this->d=mysql_fetch_object($this->c);
  51. if(is_object($this->d)) {
  52. $cusername = $this->d->username;
  53. $cpassword = $this->d->password;
  54. $cfirst_name = $this->d->first_name;
  55. $clast_name = $this->d->last_name;
  56. $cstreet = $this->d->street;
  57. $ccity = $this->d->city;
  58. $czip = $this->d->zip;
  59. $cstate = $this->d->state;
  60. $ccountry = $this->d->country;
  61. $cemail = $this->d->email;
  62. $ctelephone = $this->d->telephone;
  63. $clast_paid = $this->d->last_paid;
  64. $ccat = $this->d->cat;
  65. $csignup_date = $this->d->signup_date; 
  66. $cage = $this->d->age; 
  67. $cchest = $this->d->chest; 
  68. $cheight = $this->d->height; 
  69. $cweight = $this->d->weight; 
  70. $cwaist = $this->d->waist; 
  71. $ceyes = $this->d->eyes; 
  72. $chair = $this->d->hair; 
  73. $cdress = $this->d->dress;
  74. $cshoe = $this->d->shoe;
  75. $cmod = $this->d->mod; <----------------------------------- doda³em tê linijkê
  76. }
  77. ?>
  78. <h3>Edytuj Swoje Dane</h3>
  79. <form method=post>
  80. <?=$table2?>
  81. <tr align=center>
  82. <td colspan=2>Pola <b>pogrubione</b> s± obowi±zkowe! W razie problemów prosimy o kontakt.<p></td>
  83. </tr>
  84. <tr>
  85. <td align=right>Login:</td>
  86. <td><?=$cusername?></td></tr>
  87. <tr>
  88. <td align=right><b>Has³o:</b></td>
  89. <td><input type=text name=spassword size=35 maxlength=15 value='<?=$cpassword?>'></td></tr>
  90. <tr>
  91. <td align=right><b>Imiê:</b></td>
  92. <td><input type=text name=sfirst_name size=35 maxlength=20 value='<?=$cfirst_name?>'></td></tr>
  93. <tr>
  94. <td align=right>Nazwisko:</td>
  95. <td><input type=text name=slast_name size=35 maxlength=30 value='<?=$clast_name?>'></td></tr>
  96. <tr>
  97. <td align=right>Ulica:</td>
  98. <td><input type=text name=sstreet size=35 maxlength=50 value='<?=$cstreet?>'></td></tr>
  99. <tr>
  100. <td align=right><b>Miasto:</b></td>
  101. <td><input type=text name=scity size=35 maxlength=30 value='<?=$ccity?>'></td></tr>
  102. <tr>
  103. <td align=right><b>Województwo:</b></td>
  104. <td><input type=text name=sstate size=35 maxlength=30 value='<?=$cstate?>'></td></tr>
  105. <tr>
  106. <td align=right>Kod pocztowy:</td>
  107. <td><input type=text name=szip size=35 maxlength=10 value='<?=$czip?>'></td></tr>
  108. <tr>
  109. <td align=right><b>Kraj</b>:</td>
  110. <td><input type=text name=scountry size=35 maxlength=30 value='<?=$ccountry?>'></td></tr>
  111. <tr>
  112. <td align=right><b>Email:</b></td>
  113. <td><input type=text name=semail size=35 maxlength=75 value='<?=$cemail?>'></td></tr>
  114. <tr>
  115. <td align=right>Telefon:</td>
  116. <td><input type=text name=stelephone size=35 maxlength=12 value='<?=$ctelephone?>'></td></tr>
  117. <tr>
  118. <td align=right><b>Kategoria:</b></td>
  119. <td><? buildCatBox("scat",$ccat) ?>
  120. <tr>
  121. <td align=right><b>Rok urodzenia:</b>
  122. <td><input type=text name=sage size=35 maxlength=75 value='<?=$cage?>'></td></tr>
  123. <tr>
  124. <td align=right>Kolor oczu:
  125. <td><input type=text name=seyes size=35 maxlength=75 value='<?=$ceyes?>'></td></tr>
  126. <tr>
  127. <td align=right>kolor w³osów:
  128. <td><input type=text name=shair size=35 maxlength=75 value='<?=$chair?>'></td></tr>
  129. <tr>
  130. <td align=right><b>Biust:</b>
  131. <td><input type=text name=schest size=35 maxlength=75 value='<?=$cchest?>'></td></tr>
  132. <tr>
  133. <td align=right><b>Wzrost:</b>
  134. <td><input type=text name=sheight size=35 maxlength=75 value='<?=$cheight?>'></td></tr>
  135. <tr>
  136. <td align=right><b>Talia:</b>
  137. <td><input type=text name=sweight size=35 maxlength=75 value='<?=$cweight?>'></td></tr>
  138. <tr>
  139. <td align=right><b>Biodra:</b>
  140. <td><input type=text name=swaist size=35 maxlength=75 value='<?=$cwaist?>'></td></tr>
  141. <tr>
  142. <td align=right><b>P1:</b> <--------------------------------------------- doda³em tê linijkê i poni¿ej
  143. <td><input type=text name=sdress size=35 maxlength=75 value='<?=$cmod?>'> (Tak/Nie)</td></tr>
  144. <tr>
  145. <td align=right><b>P2</b>
  146. <td><input type=text name=sshoe size=35 maxlength=75 value='<?=$cfmod?>'></td></tr>
  147.  <tr>
  148. <td align=right><b>P3</b>
  149. <td><input type=text name=sshoe size=35 maxlength=75 value='<?=$chost?>'></td></tr>
  150. <tr>


cd kodu:

  1. <td align=right><b>P4</b>
  2. <td><input type=text name=sshoe size=35 maxlength=75 value='<?=$cta?>'></td></tr>
  3. <tr>
  4. <td> </td><td><input type=submit name=submit value='Zapisz zmiany'></td></tr>
  5. </table>
  6. </form>
  7. <?
  8. }
  9. include("include/footer.php");
  10. ?>
  11. <?
  12. function buildCatBox($name,$sel=""){
  13. ?>
  14. <SELECT NAME="<?=$name?>">
  15. <option value="">-----
  16. <?
  17. $qr1 = mysql_query("SELECT * FROM cats ORDER BY name ASC");
  18. while ($a = mysql_fetch_object($qr1)){
  19. if($sel == $a->id){
  20. echo "<OPTION VALUE="{$a->id}" SELECTED>{$a->name}</OPTION>n"; 
  21. }else{
  22. echo "<OPTION VALUE="{$a->id}">{$a->name}</OPTION>n"; 
  23. }
  24. }
  25. ?>
  26. </select>
  27. <?
  28. }
  29. function getCat($cat){
  30. $qr1 = mysql_query("SELECT name FROM cats WHERE id='$cat'");
  31. $a = mysql_fetch_object($qr1);
  32. return $a->name;
  33. }
  34. ?>


Co tu trzeba zrobiæ ¿eby wszystko dobrze dzia³a³o? sad.gif
nospor
...shoe=''WHERE....
powiina byc spacja:
....shoe='' WHERE....
rts
niestety nie pomog³o :/ A jak wywale
mod='$smod',
to wtedy siê zapisuje poprawnie ale bez zmian w polu "mod" sad.gif
nospor
mod jest slowem zastrzezonym
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
i nie powiino byc uzyte jako kolumna.
Jesli jednak nadal sie przy nim upierwasz, to musisz objac je w krzywe ciapki:
`mod`
rts
Wielkie dziêki biggrin.gif
siemakuba
Z góry excuse me za OffTopic, ale nie mog³em siê powstrzymaæ :):)
Cytat(nospor @ 30.10.2006, 23:26:13 ) *
(...) w krzywe ciapki:

Nigdy nie wiedzia³em jak spolszczyæ "backticks", a to porpostu "krzywe ciapki" :)

pozdr.
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.