Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [HTML][MySQL][PHP]Dlaczego czyści dane z formularza?, Formularz nie przysyła edytowanych danych
konradkw
post 27.08.2012, 22:29:00
Post #1





Grupa: Zarejestrowani
Postów: 131
Pomógł: 0
Dołączył: 31.05.2010

Ostrzeżenie: (0%)
-----


Co tutaj jest nie tak?
Cokolwiek robię przesyłane sa tylko i wyłącznie czyste dane - dlaczego?

  1. if (isset($_POST['edit']))
  2. {
  3. $id = $_POST['id'];
  4. $ttt = mysql_query ("SELECT * FROM `vivian_articles` WHERE `id` = '$id'");
  5. while ($tt = mysql_fetch_array($ttt, MYSQL_ASSOC))
  6.  
  7. {
  8. echo '<center><FORM action="index.php?admin=articles" method="post"><input type="hidden" name="id" value="'.$tt['id'].'"><table>
  9.  
  10. <tr><td>Title</td><td><input name="title" type="text" size="98" value="'.$tt['title'].'"></td></tr>
  11.  
  12. <tr><td>Description</td><td><textarea name="description" cols="78">'.$tt['description'].'</textarea></td></tr>
  13. <tr><td>Key words:</td>
  14. <td>
  15. <input type="text" name="key1" size="15" value="'.$tt['key1'].'">
  16. <input type="text" name="key2" size="15" value="'.$tt['key2'].'">
  17. <input type="text" name="key3" size="15" value="'.$tt['key3'].'">
  18. <input type="text" name="key4" size="15" value="'.$tt['key4'].'">
  19. <input type="text" name="key5" size="15" value="'.$tt['key5'].'"><br>
  20. <input type="text" name="key6" size="15" value="'.$tt['key6'].'">
  21. <input type="text" name="key7" size="15" value="'.$tt['key7'].'">
  22. <input type="text" name="key8" size="15" value="'.$tt['key8'].'">
  23. <input type="text" name="key9" size="15" value="'.$tt['key9'].'">
  24. <input type="text" name="key10" size="15" value="'.$tt['key10'].'">
  25. </td></tr>
  26.  
  27. <tr><td>Article budy:</td><td><textarea name="body" cols="78" rows="15">'.$tt['body'].'</textarea></td></tr>
  28.  
  29. <tr><td></td><td><center><input type="submit" name="submitedit" value="Submit changes"></center></td></tr>
  30. </table></center>';
  31. }
  32. }
  33. /////////////////////////////////////////////////////////////////////////////////////////////
  34.  
  35. if (isset($_POST['submitedit']))
  36. {
  37. $id = $_POST['id'];
  38. $t = $_POST['title'];
  39. $d = $_POST['description'];
  40. $k1 = $_POST['key1'];
  41. $k2 = $_POST['key2'];
  42. $k3 = $_POST['key3'];
  43. $k4 = $_POST['key4'];
  44. $k5 = $_POST['key5'];
  45. $k6 = $_POST['key6'];
  46. $k7 = $_POST['key7'];
  47. $k8 = $_POST['key8'];
  48. $k9 = $_POST['key9'];
  49. $k10 = $_POST['key10'];
  50. $b = $_POST['body'];
  51.  
  52. $update = mysql_query("UPDATE `vivian_articles` SET `title` = '$t', `description` = '$d', `key1` = '$k1', `key2` = '$k2', `key3` = '$k3', `key4` = '$k4', `key5` = '$k5', `key6` = '$k6', `key7` = '$k7', `key8` = '$k8', `key9` = '$k9', `key10` = '$k10', `body` = '$b' WHERE `id` = '$id'");
  53.  
  54. if ($update) {
  55. echo "<center>UPDATED OK!</center>";
  56. } else {
  57. echo mysql_error(); echo '<p>Error! Please try again</p>';
  58. }
  59.  
  60. }
  61.  


Ten post edytował konradkw 27.08.2012, 22:29:52
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
peter13135
post 27.08.2012, 22:46:03
Post #2





Grupa: Zarejestrowani
Postów: 1 447
Pomógł: 191
Dołączył: 26.03.2008

Ostrzeżenie: (0%)
-----


Co to są "czyste dane" ?

problem jest w zapisywaniu danych do bazy, czy odczytywaniu ?


--------------------
:)
Go to the top of the page
+Quote Post
konradkw
post 27.08.2012, 23:26:34
Post #3





Grupa: Zarejestrowani
Postów: 131
Pomógł: 0
Dołączył: 31.05.2010

Ostrzeżenie: (0%)
-----


ogólnie to jest mały skrypt który po wybraniu przycisku edit przy wyświetlonych z bazy (wcześniej dodanych) pozycji, wyswietla dane w formularzu tak że da się je edytować z tym że po edycji wpis zapisuje się całkowicie wyczyszczony. czyli przy zapisie jest problem.
Go to the top of the page
+Quote Post
untorched
post 27.08.2012, 23:34:08
Post #4





Grupa: Zarejestrowani
Postów: 318
Pomógł: 76
Dołączył: 27.12.2011
Skąd: Dąbrowa Górnicza

Ostrzeżenie: (0%)
-----


Sprawdź co zawiera $_POST, więc
  1. if (isset($_POST['submitedit']))
  2. {
  3. var_dump($_POST);
Jeśli zawiera te dane, które potrzebujesz to błąd leży w przekazywaniu zawartości zmiennych do zapytania(w podanym skrypcie linijka 52)
Go to the top of the page
+Quote Post
konradkw
post 27.08.2012, 23:42:13
Post #5





Grupa: Zarejestrowani
Postów: 131
Pomógł: 0
Dołączył: 31.05.2010

Ostrzeżenie: (0%)
-----


Jako dane wpisałem nazwy (lub skróty) pól aby było widać co jest gdzie.

  1. array(15) { ["id"]=> string(2) "22" ["title"]=> string(5) "Title" ["description"]=> string(11) "Description" ["key1"]=> string(2) "k1" ["key2"]=> string(2) "k2" ["key3"]=> string(2) "k3" ["key4"]=> string(2) "k4" ["key5"]=> string(2) "k5" ["key6"]=> string(2) "k6" ["key7"]=> string(2) "k7" ["key8"]=> string(2) "k8" ["key9"]=> string(2) "k9" ["key10"]=> string(3) "k10" ["body"]=> string(4) "BODY" ["submitedit"]=> string(14) "Submit changes" }


Jeśli chodzi o linijkę 52 - to nie widzę błędu.
Go to the top of the page
+Quote Post
untorched
post 27.08.2012, 23:59:48
Post #6





Grupa: Zarejestrowani
Postów: 318
Pomógł: 76
Dołączył: 27.12.2011
Skąd: Dąbrowa Górnicza

Ostrzeżenie: (0%)
-----


Linijkę 52:
  1. $update = mysql_query("UPDATE `vivian_articles` SET `title` = '$t', `description` = '$d', `key1` = '$k1', `key2` = '$k2', `key3` = '$k3', `key4` = '$k4', `key5` = '$k5', `key6` = '$k6', `key7` = '$k7', `key8` = '$k8', `key9` = '$k9', `key10` = '$k10', `body` = '$b' WHERE `id` = '$id'");
zamień na:
  1. $sql = "UPDATE `vivian_articles` SET `title` = '$t', `description` = '$d', `key1` = '$k1', `key2` = '$k2', `key3` = '$k3', `key4` = '$k4', `key5` = '$k5', `key6` = '$k6', `key7` = '$k7', `key8` = '$k8', `key9` = '$k9', `key10` = '$k10', `body` = '$b' WHERE `id` = '$id'";
  2. echo $sql;
  3. $update = mysql_query($sql);
I sprawdź czy zapytanie które Ci wyrzuca jest poprawne, tj. nie ma w nim pustych wartości

Ten post edytował untorched 28.08.2012, 00:02:53
Go to the top of the page
+Quote Post
konradkw
post 28.08.2012, 00:12:59
Post #7





Grupa: Zarejestrowani
Postów: 131
Pomógł: 0
Dołączył: 31.05.2010

Ostrzeżenie: (0%)
-----


teraz zapisuje zmiany dobrze. dziękuję!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 04:20