Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][MYSQL] Dziwny problem z komentarzami...
-Uerty-
post
Post #1





Goście







Mam problem z komentarzami. Piszę system newsów i chcę zrobić coś takiego jak w większości systemów, że wyświetla komentarze które zostały wprowadzone do odpowiedniego newsa, ale z tym sobie poradzę. Problem jest w czymś innym. Jak klikam na newsa o id= 1 i piszę komentarz i wysyłam go to do bazy to zamiast o id równym newsa tego co kliknąłem, trafia komentarz o id newsa równym 2. Bazę mam tak skonstruowaną żeby jak najmniej COUNT() używać smile.gif , więc po to pole newsid jest. Co jest tego przyczyną? Cały kod:

  1. <?php
  2.  
  3. mysql_connect('localhost','root','mentormiszcz1e');
  4. mysql_select_db('system');
  5.  
  6. $select= "SELECT id,subject,content,author,date FROM news";
  7. $display= mysql_query($select);
  8.  
  9. while ($show= mysql_fetch_assoc($display)) {
  10.  
  11. $_GET['id']= $show['id'];
  12. $id= htmlspecialchars($_GET['id']);
  13.  
  14. echo '<div id="subject">'. $show['subject'] . '</div>'
  15. . '<div id="content">' . $show['content'] . '</div>'
  16. . '<div id="authdate">' . 'Author: ' . $show['author'] . 'Added: ' . $show['date']
  17. . '<a href="show.php?show=true&amp;id='.$id.'">comments</a>'
  18.  . '</div>';
  19.  
  20.  
  21. } // end while $show
  22.  
  23. if (htmlspecialchars($_GET['show'])== "true") {
  24.  
  25. if ($_GET['id']) {
  26. echo '<form action="show.php?show=true&amp;id='.$id.'" method="post">
  27. <div id="form">
  28. <label>Nick: <input type="text" name="author" /></label>
  29. <textarea name="content" cols="35" rows="15"></textarea>
  30. <input type="submit" value="Add my comment" />
  31. </div>
  32. </form>';
  33. }
  34.  
  35. if (!empty($_POST['author']) && !empty($_POST['content'])) {
  36.  
  37. $date= date("d.m.Y");
  38. $insert= "INSERT INTO `comments` (author,content,date,newsid) VALUES
  39. ('".$_POST['author']."','".$_POST['content']."','$date','$id')";
  40. mysql_query($insert);
  41. } // end empty $_POST
  42.  
  43. } // end $_GET['show']== "true"
  44.  
  45. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 21.08.2025 - 01:34