Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z UPDATE
krzywy853
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 7.10.2013

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


Mam taki kod:
  1. <?php
  2. include ("header.php");
  3. error_reporting(E_ALL | E_STRICT | E_NOTICE);
  4. ini_set("display_errors", "1");
  5. $news_id = $_GET['news_id'];
  6. $query = mysqli_query ($connect, "SELECT `news_id`, `news_subject`, `news_image`, `news_cat`, `news_desc` FROM news WHERE news_id=".$_GET['news_id']."") or die ("<p class='blad'>Wystąpił błąd podczas pobierania wpisów z bazy.</p> ".mysqli_connect_error()."");
  7.  
  8. $news = mysqli_fetch_array($query);
  9. $news_subject = htmlspecialchars ($news['news_subject']);
  10. $news_image = htmlspecialchars ($news['news_image']);
  11. $news_cat = htmlspecialchars ($news['news_cat']);
  12. $news_desc = htmlspecialchars ($news['news_desc']);
  13.  
  14. echo "<form name='add_news' action='news.php?news_id=".$news_id."' method='post'>
  15. <div class='box'>
  16. <h1>Dodaj newsa</h1>
  17. <label>
  18. <span>Tytuł :</span>
  19. <input type='text' class='wpis' name='news_subject' id='' value='".$news_subject."'/>
  20. </label>
  21. <label>
  22. <span>Okładka :</span>
  23. <input type='text' class='wpis' name='news_image' id='' value='".$news_image."'/>
  24. </label>
  25. <label>
  26. <span>Kategoria :</span>
  27. <input type='radio' class='wpis' name='' id=''/>
  28. <input type='radio' class='wpis' name='' id=''/>
  29. <input type='radio' class='wpis' name='' id=''/>
  30. <input type='radio' class='wpis' name='' id=''/>
  31. </label>
  32. <label>
  33. <span>Treść :</span>
  34. <textarea class='wiadomosc' name='news_desc' id=''>".stripslashes($news_desc)."</textarea>
  35. <input type='submit' class='button' value='Wyślij'/>
  36. </label>
  37. </div>
  38.  
  39.  
  40. </form>";
  41. if (!empty($_POST)) {
  42. $_toDB['news_subject']= mysqli_real_escape_string ($connect, $_POST['news_subject']);
  43. $_toDB['news_image']= mysqli_real_escape_string ($connect, $_POST['news_image']);
  44. $_toDB['news_cat']= mysqli_real_escape_string ($connect, $_POST['news_cat']);
  45. $_toDB['news_desc']= mysqli_real_escape_string ($connect, $_POST['news_desc']);
  46. mysqli_query($connect, "UPDATE news SET news_subject = ".$_toDB['news_subject'].", news_image = ".$_toDB['news_image'].", news_cat = ".$_toDB['news_cat'].", news_desc = ".$_toDB['news_desc']." WHERE news_id = ".$news_id."");
  47. }
  48. var_dump($_POST);
  49.  
  50.  
  51.  
  52.  
  53. include("footer.php");
  54. ?>

Powinien on aktualizować dane z formularza jednakże tak się nie dzieje. Co jest nie tak?

Ten post edytował krzywy853 31.10.2013, 20:39:08
Go to the top of the page
+Quote Post
SmokAnalog
post
Post #2





Grupa: Zarejestrowani
Postów: 1 707
Pomógł: 266
Dołączył: 3.07.2012
Skąd: Poznań

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


Do wstawiania kodu PHP służy tag [ php ].

Pierwsze co widzę, to że w zapytaniu masz łańcuchy znaków luzem, a nie w apostrofach.
Go to the top of the page
+Quote Post
krzywy853
post
Post #3





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 7.10.2013

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


Nic to nie dało
Go to the top of the page
+Quote Post
com
post
Post #4





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


białe znaki po mysqli_real_escape_string wink.gif
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 Aktualny czas: 20.08.2025 - 08:44