Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> problem z updatowaniem kolumn z pziomu php
SoulRipper
post 16.10.2004, 09:11:21
Post #1





Grupa: Zarejestrowani
Postów: 86
Pomógł: 0
Dołączył: 15.03.2003
Skąd: lodz

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


mam takie oto cos:
  1. <?
  2. $query = &#092;"select * from art where id='$ajdi'\";
  3.  
  4. $commit = mysql_query($query);
  5. $fetch = mysql_fetch_array($commit);
  6. $id=$fetch['id'];
  7. $autor=$fetch['autor'];
  8. $art=$fetch['art'];
  9.  
  10. echo &#092;"
  11.  
  12. <form method='post' action='modify.php'>
  13. Autor<input type='text' name='autor' value='$autor'><br>
  14. ID artykolu<input type='text' name='id' value='$ajdi' disabled><br>
  15. <textarea name='art' cols='60' rows='40'>$art</textarea><br>
  16. <input type='submit' name='go' value='dalej'>
  17.  
  18. </form>&#092;";
  19.  
  20. $button = $_POST['go'];
  21. $art = $_POST['art'];
  22. $autor = $_POST['autor'];
  23. if($button == &#092;"dalej\")
  24. {
  25.  
  26. $query = &#092;"updade art set art='qwewerewr' \";
  27. $result = mysql_query ($query);
  28. echo $art.&#092;"<br>\".$autor.\"<br>\".$ajdi.\"<br>\".mysql_affected_rows();
  29.  
  30. }
  31. ?>


problem polega na tym ze nie chce dzialac zapytanie update
caly scrypt polega na pobieraniu z bazy danych wartosci art oraz autor a nastepnie wyswietleniu ich w odpowiednich polach tekstowych, pozniej nacisniecie przycisku 'dalej' powinno updatowac kolumne art oraz kolumne autor o okreslonym id o te wartosci wpisane w pola tekstowe

ps.
polaczenie z baza danych jest zapisana w innym pliku ktory jest polaczony z tym
za pomoca funkcji include

Ten post edytował SoulRipper 16.10.2004, 09:43:05
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 7)
bela
post 16.10.2004, 09:28:22
Post #2


Administrator PHPedia.pl


Grupa: Developerzy
Postów: 1 102
Pomógł: 2
Dołączył: 14.09.2003

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


wydrukuj zmienne post i zobacz czy są kwiatki dry.gif
  1. <?php
  2. foreadch($_POST as $p) {
  3. print $p;
  4. }
  5. ?>


--------------------
Go to the top of the page
+Quote Post
SoulRipper
post 16.10.2004, 09:42:28
Post #3





Grupa: Zarejestrowani
Postów: 86
Pomógł: 0
Dołączył: 15.03.2003
Skąd: lodz

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


dzialaja

nie dziala jedynie zmienna 'id'

ps. zmienilem troche kod;
Go to the top of the page
+Quote Post
borec
post 16.10.2004, 09:55:00
Post #4





Grupa: Zarejestrowani
Postów: 260
Pomógł: 0
Dołączył: 18.07.2003
Skąd: Tarnów

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


  1. <?
  2. $query = &#092;"select `id`, `autor`, `art` from art where id='$ajdi'\";
  3. // po co wyciagac wartosci wszystkich pol?
  4.  
  5. $commit = mysql_query($query);
  6. $fetch = mysql_fetch_array($commit);
  7.  
  8. // po co dodatkowe zmienne, nie mozesz uzyc dalej tablicy $fetch?
  9. $id=$fetch['id'];
  10. $autor=$fetch['autor'];
  11. $art=$fetch['art'];
  12.  
  13. echo &#092;"
  14.     
  15.     <form method='post' action='modify.php'>
  16.     Autor<input type='text' name='autor' value='$autor'><br>&#092;";
  17.  
  18.     // skad sie tu wziela zmienna $ajdi? nie powinno byc $id?
  19. echo &#092;"ID artykolu<input type='text' name='id' value='$id' disabled><br>
  20.     <textarea name='art' cols='60' rows='40'>$art</textarea><br>
  21.     <input type='submit' name='go' value='dalej'>
  22.         
  23.     </form>&#092;";
  24.  
  25. $button = $_POST['go'];
  26. $art = $_POST['art'];
  27. $autor = $_POST['autor'];
  28. if($button == &#092;"dalej\")
  29. {
  30.  
  31.     // zdaje sie ze brakuje warunku z id i zmienienia wartosci pola autor
  32.     $query = &#092;"updade art set art='$art', `autor` = '$autor' where `id` = {$_POST['id']} limit 1\";
  33.     $result = mysql_query ($query);
  34.     echo $art.&#092;"<br>\".$autor.\"<br>\".$ajdi.\"<br>\".mysql_affected_rows();
  35.  
  36. }
  37. ?>


Ten post edytował borec 16.10.2004, 09:56:06


--------------------
Gentoo Linux 64bit / PHP 5.2 / MySQL 5.1
-> Administracja serwerami Linux i FreeBSD
Go to the top of the page
+Quote Post
SoulRipper
post 16.10.2004, 10:14:14
Post #5





Grupa: Zarejestrowani
Postów: 86
Pomógł: 0
Dołączył: 15.03.2003
Skąd: lodz

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


1) w tabeli sa 4 kolumny : 'id','autor','art','data'
pozniej moze jeszcze dodam kiedy byl utworzony dany artykol
2) do dodatkowych zmiennych przydzielilem zeby uzyskac czytelnosc zapisu

3) $ajdi wziela sie z innego formularza(zamieszczonego na tej samej stronie)
ktorego zadaniem jest zmiana id aktualnego artykolu. w sumie fakt ze nie bardzo jest ona potrzebna ale teraz najbardziej zalezy mi zeby scrypt dzialal, a dop. pozniej zajme sie optymalizacja kodu.


EDIT:
dobra poradzilem juz sobie z problemem, chodzilo o problem w zapytaniu
bylo "UPDADE" a powinno byc "UPDATE"-lama ze mnie withstupidsmiley.gif

Ten post edytował SoulRipper 16.10.2004, 10:23:10
Go to the top of the page
+Quote Post
borec
post 16.10.2004, 10:20:44
Post #6





Grupa: Zarejestrowani
Postów: 260
Pomógł: 0
Dołączył: 18.07.2003
Skąd: Tarnów

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


czyli dalej nie dziala? dziadzia? moze pokaz reszte kodu


--------------------
Gentoo Linux 64bit / PHP 5.2 / MySQL 5.1
-> Administracja serwerami Linux i FreeBSD
Go to the top of the page
+Quote Post
borec
post 16.10.2004, 10:27:16
Post #7





Grupa: Zarejestrowani
Postów: 260
Pomógł: 0
Dołączył: 18.07.2003
Skąd: Tarnów

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


literowki - plaga programistow winksmiley.jpg


--------------------
Gentoo Linux 64bit / PHP 5.2 / MySQL 5.1
-> Administracja serwerami Linux i FreeBSD
Go to the top of the page
+Quote Post
SoulRipper
post 16.10.2004, 10:31:52
Post #8





Grupa: Zarejestrowani
Postów: 86
Pomógł: 0
Dołączył: 15.03.2003
Skąd: lodz

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


dobra jeden problem rozwiazny, teraz rodzi sie inny pomimo tego ze jest przypisana zmienna do $id potrzebna w zapytaniu:
  1. <?php
  2.  
  3. $query = &#092;"update art set art='$art' and autor='$autor' where id='$id' \";
  4.  
  5. ?>

problem polega na tym ze mysql)affected_rows() wyswietla 0
wnioskuje z tego ze nie moze odnalesc tej zmiennej $id.

a oto kompletny kod

  1. <?
  2. include &#092;"include.php\" ;
  3.  
  4. //kod odpowiedzialny za zmiane id modyfikowanego formularza
  5. $zmien_id = $_POST['change_id'];
  6. $button_klik = $_POST['zmiana'];
  7. if ($button_klik == &#092;"go\")
  8. {
  9.     $ajdi = $zmien_id;
  10. }
  11. //kod odpowiedzailny za modyfikowanie wpisow
  12.  
  13. $query = &#092;"select * from art where id='$ajdi'\";
  14.  
  15. $commit = mysql_query($query);
  16. $fetch = mysql_fetch_array($commit);
  17. $id=$fetch['id'];
  18. $autor=$fetch['autor'];
  19. $art=$fetch['art'];
  20.  
  21. echo &#092;"
  22.     
  23.     <form method='post' action='modify.php'>
  24.     Autor<input type='text' name='autor' value='$autor'><br>
  25.     ID artykolu<input type='text' name='id' value='$ajdi' disabled><br>
  26.     <textarea name='art' cols='60' rows='40'>$art</textarea><br>
  27.     <input type='submit' name='go' value='dalej'>
  28.         
  29.     </form>&#092;";
  30.  
  31. $button = $_POST['go'];
  32. $art = $_POST['art'];
  33. $autor = $_POST['autor'];
  34. if($button == &#092;"dalej\")
  35. {
  36.  
  37.     $query = &#092;"update art set art='$art' and autor='$autor' where id='$id' \";
  38.     $result = mysql_query ($query);
  39.     echo $art.&#092;"<br>\".$autor.\"<br>\".$ajdi.\"<br>\".mysql_affected_rows();
  40.  
  41. }
  42.  
  43.  
  44. ?>
  45.  
  46. <form method=\"post\" action=\"modify.php\">
  47. <br>skocz do ID artykolu:<input type=\"text\" name=\"change_id\" size=\"3\" value=\"<? echo $id; ?>\"><br>
  48. <input type=\"submit\" name=\"zmiana\" value=\"go\">
  49. </form>
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: 26.06.2025 - 10:53