Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Update bazy danych - problem ze zmiana
Forum PHP.pl > Forum > Przedszkole
szczalpi
Witam
Poniżej podaje jak mam kod do update bazy. Otóż to. Pobiera mi wszystkie dane z bazy, ale niestety nie zmienia wpisów, które edytowałem.
NIe wiem gdzie tkwi problem. Czy możecie pomóc mi i zobaczyć gdzie tkwi problem.
Pozdrawiam
  1. $pokaz = $_GET['pokaz'];
  2.  
  3. $sql="select * from atrakcje where id='$pokaz'";
  4. $result=mysql_query($sql);
  5. $row=mysql_fetch_array($result);
  6.  
  7. if(isset($_GET['changes'])):
  8. {
  9.  
  10. $id = $_GET['id'];
  11. $kat = $_GET['kat'];
  12. $tytul =$_GET['tytul'];
  13. $ul = $_GET['ul'];
  14. $miasto = $_GET['miasto'];
  15. $gmina = $_GET['gmina'];
  16. $powiat = $_GET['powiat'];
  17. $wojewodztwo = $_GET['wojewodztwo'];
  18. $opis = $_GET['opis'];
  19. $www = $_GET['www'];
  20. $zdjecie = $_GET['zdjecie'];
  21. $gmx = $_GET['gmx'];
  22. $gmy = $_GET['gmy'];
  23. $counter = $_GET['counter'];
  24.  
  25. $sql="update atrakcje set id='$id' where id='$pokaz'";
  26. mysql_query($sql);
  27.  
  28. $sql="update atrakcje set kat='$kat' where id='$pokaz'";
  29. mysql_query($sql);
  30.  
  31. $sql="update atrakcje set tytul='$tytul' where id='$pokaz'";
  32. mysql_query($sql);
  33.  
  34. $sql="update atrakcje set ul='$ul' where id='$pokaz'";
  35. mysql_query($sql);
  36.  
  37. $sql="update atrakcje set miasto='$miasto' where id='$pokaz'";
  38. mysql_query($sql);
  39.  
  40. $sql="update atrakcje set gmina='$gmina' where id='$pokaz'";
  41. mysql_query($sql);
  42.  
  43. $sql="update atrakcje set powiat='$powiat' where id='$pokaz'";
  44. mysql_query($sql);
  45.  
  46. $sql="update atrakcje set wojewodztwo='$wojewodztwo' where id='$pokaz'";
  47. mysql_query($sql);
  48.  
  49. $sql="update atrakcje set opis='$opis' where id='$pokaz'";
  50. mysql_query($sql);
  51.  
  52. $sql="update atrakcje set www='$www' where id='$pokaz'";
  53. mysql_query($sql);
  54.  
  55. $sql="update atrakcje set zdjecie='$zdjecie' where id='$pokaz'";
  56. mysql_query($sql);
  57.  
  58. $sql="update atrakcje set gmx='$gmx' where id='$pokaz'";
  59. mysql_query($sql);
  60.  
  61. $sql="update atrakcje set gmy='$gmy' where id='$pokaz'";
  62. mysql_query($sql);
  63.  
  64. $sql="update atrakcje set counter='$counter' where id='$pokaz'";
  65. mysql_query($sql);
  66.  
  67.  
  68. echo "<p align=\"center\">Twoje dane zostały zmienione.</p>";
  69. echo $row['id'];
  70. }
  71. else:
  72. {
  73. ### wyświetlenie wpisu #######################################################?>
  74. <form action="edycja.php" method="get">
  75. <table width=450 align="center">
  76. <tr><td align="center" height=0><p>Tutaj możesz zmienić i aktualizować swoje dane:</table>
  77.  
  78. <table width="750" align="center">
  79. <tr>
  80. <td>&nbsp;
  81. <tr>
  82. <td class="label">Kategoria:</td><td><input class="long" type="text" name="id" value="<? echo $row['id']; ?>">
  83. </tr><br/>
  84. <tr>
  85. <td class="label">Kategoria:</td><td><input class="long" type="text" name="kat" value="<? echo $row['kat']; ?>">
  86. </tr><br/>
  87. <tr>
  88. <td class="label">Tytul:</td><td><input class="long" type="text" name="tytul" value="<? echo $row['tytul']; ?>">
  89. </tr><br/>
  90. <tr>
  91. <td class="label">Ulica:</td><td><input class="long" type="text" name="ul" size="40" value="<? echo $row['ul']; ?>">
  92. </tr><br/>
  93.  
  94. <tr>
  95. <td class="label">miasto:</td><td><input class="long" type="text" name="miasto" value="<? echo $row['miasto']; ?>">
  96. </tr><br/>
  97. <tr>
  98. <td class="label">gmina:</td><td><input class="long" type="text" name="gmina" value="<? echo $row['gmina']; ?>">
  99. </tr><br/>
  100. <tr>
  101. <td class="label">powiat:</td><td><input class="long" type="text" name="powiat" value="<? echo $row['powiat']; ?>">
  102. </tr><br/>
  103. <tr>
  104. <td class="label">wojewodztwo:</td><td><input class="long" type="text" name="wojewodztwo" value="<? echo $row['wojewodztwo']; ?>">
  105. </tr><br/>
  106. <tr>
  107. <td class="label">opis:</td><td><input class="long" type="text" name="opis" value="<? echo $row['opis']; ?>">
  108. </tr><br/>
  109. <tr>
  110. <td class="label">www:</td><td><input class="long" type="text" name="www" value="<? echo $row['www']; ?>">
  111. </tr><br/>
  112. <tr>
  113. <td class="label">Czdjecie:</td><td><input class="long" type="text" name="zdjecie" value="<? echo $row['zdjecie']; ?>">
  114. </tr><br/>
  115. <tr>
  116. <td class="label">gmx:</td><td><input class="long" type="text" name="gmx" value="<? echo $row['gmx']; ?>">
  117. </tr><br/>
  118. <tr>
  119. <td class="label">gmy:</td><td><input class="long" type="text" name="gmy" value="<? echo $row['gmy']; ?>">
  120. </tr><br/>
  121. <tr>
  122. <td class="label">counter:</td><td><input class="long" type="text" name="counter" value="<? echo $row['counter']; ?>">
  123. </tr><br/>
  124.  
  125. <tr><td><td align="center"><input type="submit" name="changes" value="ok">
  126.  
  127.  
  128. </form>
  129. </table>
  130. <?
  131. }
  132. endif;
CuteOne
  1. UPDATE atrakcje SET www='$www', miasto='$miasto', opis='$opis' (itp.) WHERE id='$pokaz'

zamiast 50 zapytań


@edit wiem, wiem. wszystko w swoim czasie wink.gif


@szczapi zobacz jak zapisywać if/else

endif i else: raczej nie pasuje do klamerek smile.gif
nospor
@CuteOne ale wiesz, ze na chwile obecna ta poprawka nic zmieni procz mniejszej ilosci kodu? wink.gif

Co do problemu:
Temat: Jak poprawnie zada pytanie
szczalpi
  1. $pokaz = $_GET['pokaz'];
  2.  
  3. $sql="select * from atrakcje where id='$pokaz'";
  4. $result=mysql_query($sql);
  5. $row=mysql_fetch_array($result);
  6.  
  7. if(isset($_GET['changes'])):
  8. {
  9.  
  10. $id = $_GET['id'];
  11. $kat = $_GET['kat'];
  12.  
  13.  
  14. $sql="update atrakcje set id='$id' where id='$pokaz'";
  15. mysql_query($sql);
  16.  
  17. $sql="update atrakcje set kat='$kat' where id='$pokaz'";
  18. mysql_query($sql);
  19.  
  20.  
  21.  
  22. echo "<p align=\"center\">Twoje dane zostały zmienione.</p>";
  23. echo $row['id'];
  24. }
  25. else:
  26. {
  27. ### wyświetlenie wpisu #######################################################?>
  28. <form action="edycja.php" method="get">
  29. <table width=450 align="center">
  30. <tr><td align="center" height=0><p>Tutaj możesz zmienić i aktualizować swoje dane:</table>
  31.  
  32. <table width="750" align="center">
  33. <tr>
  34. <td>&nbsp;
  35. <tr>
  36. <td class="label">Kategoria:</td><td><input class="long" type="text" name="id" value="<? echo $row['id']; ?>">
  37. </tr><br/>
  38. <tr>
  39. <td class="label">Kategoria:</td><td><input class="long" type="text" name="kat" value="<? echo $row['kat']; ?>">
  40. </tr><br/>
  41.  
  42.  
  43.  
  44. <tr><td align="center"><input type="submit" name="changes" value="ok">
  45. </td>
  46. </tr>
  47. </form>
  48. </table>
  49. <?
  50. }
  51. endif;
nospor
W ogole nie zastosowales sie do tematu do ktorego cie odeslalem..... czego nie zrozumiales?

ps: jak wysylasz forma ze zmianami, to POKAZ tez by wypadalo przeslac ponownie...
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.