Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MYSQL] Problem z update..
-Dervtty-
post
Post #1





Goście







Przy próbie update newsa przy jego edycji pojawia się problem. Po prostu go nie aktualizuje. Co jest tego przyczyną? Próbowałem już na wiele sposobów rozwiązać to ale dalej nic z tego. Cały kod:

  1. <?php
  2.  
  3.  
  4. if (!isset($_SESSION['admin'])) {
  5. header ("Location: admin.html");
  6. }
  7.  
  8. else {
  9.  
  10. mysql_connect ('localhost','root','mentormiszcz1e');
  11. mysql_select_db('system');
  12. include ("main.php");
  13.  
  14. switch ($_GET['mod']) {
  15.  
  16. default:
  17. echo 'Yo, ' . $_SESSION['admin'];
  18.  
  19. break;
  20.  
  21. case 'addnews':
  22. echo '<div id="use">
  23. <form action="admin.php?mod=addnews" method="post">
  24. <div id="form">
  25. <label>Subject: <input type="text" name="subject" size="60" /></label>
  26. <textarea name="message" rows="15" cols="55"></textarea>
  27. <input type="submit" value="Add" />
  28. </div>
  29. </form>
  30. </div>';
  31.  
  32. if (empty($_POST['subject']) && empty ($_POST['message'])) {
  33. echo 'Type all';
  34. }
  35.  
  36. else {
  37. $date= date ("d.m.Y");
  38. $insert= "INSERT INTO news (subject,content,author,date)
  39. VALUES ('".$_POST['subject']."','".$_POST['message']."'
  40. ,'".$_SESSION['admin']."','$date')";
  41. mysql_query ($insert);
  42. echo 'News has been added';
  43. }
  44.  
  45. break;
  46.  
  47. case 'editnews':
  48.  
  49. $id= htmlspecialchars($_GET['id']);
  50.  
  51. if ($_GET['edit']== "true") {
  52.  
  53. $selectedit= "SELECT id,subject,content FROM news WHERE id='$id'";
  54. htmlspecialchars($selectedit);
  55. $edit= mysql_query($selectedit);
  56. $edit= mysql_fetch_assoc($edit);
  57. $subject= $edit['subject'];
  58. $content= $edit['content'];
  59.  
  60. if (empty($_POST['editsubject']) && empty($_POST['editcontent'])) {
  61. echo '<form action="admin.php?mod=editnews&edit=true&id='.$id.'" method="post">
  62. <div id="form">
  63. <input type="text" name="editsubject" value="'.$subject.'" />
  64. <textarea name="editcontent" rows="15" cols="55">' . $content . '</textarea>' .
  65. '<input type="submit" value="Save" />' .
  66. '</div>
  67. </form>';
  68. }
  69. else {
  70. $update= "UPDATE subject,content SET subject= '".$_POST['editsubject']."',
  71. content= '".$_POST['editcontent']."' WHERE id= '$id'";
  72. mysql_query($update);
  73. echo 'News has been updated';
  74. }
  75.  
  76.  
  77. }
  78.  
  79. $select= "SELECT id,subject,author,date FROM news";
  80. $sh= mysql_query($select);
  81.  
  82. while ($show= mysql_fetch_assoc($sh)) {
  83.  
  84. $_GET['id']= $show['id'];
  85. echo '<form action="admin.php?mod=editnews" method="post">
  86. <div id="form">
  87. <input type="checkbox" name="select" />
  88. </div>
  89. </form>' .'<a href="admin.php?mod=editnews&edit=true&id='.$_GET['id'].'">'. $show['subject'] . '</a>' 
  90. . $show['author'] . $show['date'];
  91.  
  92. }
  93. break;
  94.  
  95. } // end switch
  96.  
  97. } // end else
  98.  
  99. ?>
Go to the top of the page
+Quote Post
Czapla
post
Post #2





Grupa: Zarejestrowani
Postów: 130
Pomógł: 3
Dołączył: 10.12.2007
Skąd: Bielsko-Biała

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


popatrz na swój update (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

  1. <?php
  2. $update= "UPDATE subject,content SET subject= '".$_POST['editsubject']."',
  3. ?>


Ten post edytował Czapla 24.06.2008, 10:45:14
Go to the top of the page
+Quote Post
-Dervtty-
post
Post #3





Goście







Niby normalnie jest, ale coś nie robi update. Update jest dobrze skonstruowany, tak mi się wydaje przynajmniej.
Go to the top of the page
+Quote Post
Czapla
post
Post #4





Grupa: Zarejestrowani
Postów: 130
Pomógł: 3
Dołączył: 10.12.2007
Skąd: Bielsko-Biała

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


zapytanie jest źle skonstruowane

zobacz jaka jest skladnia UPDATE
Go to the top of the page
+Quote Post
-Dervtty-
post
Post #5





Goście







No faktycznie. Głupi błąd. Teraz chodzi normalnie jak przepisałem jeszcze raz od nowa. Dzięki (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 23.08.2025 - 02:19