Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. Form:
  2.  
  3. echo "<form action='forums.php' method='post'>";
  4. echo "<input type='hidden' name='forum' value='" . $_GET['forum'] . "'>";
  5. echo "Subject: <input type='text' style='width: 95%;' name='subject' /><br />";
  6. echo "<textarea style='width: 95%;' rows='10' name='content'></textarea><br />";
  7. echo "<input type='submit' name='newthread' value='Post' /><br />";
  8. echo "</form>";
  9.  
  10. Catcher:
  11.  
  12. if (isset($_POST['newthread'])) {
  13.     $posted = date("Y-m-d H:i:s", time());
  14.     $poster = getval("users", "id", "username", $_SESSION['user']);
  15.     $post = $mysqli->real_escape_string(stripslashes($_POST['content']));
  16.     $title = $mysqli->real_escape_string(stripslashes($_POST['subject']));
  17.     echo "<!-- Variables: ";
  18.     print_r($_POST);
  19.     echo "-->";
  20.     $result = $mysqli->query("INSERT INTO posts (content, posted, poster, forum) VALUES (" . $post . ", $posted,  $poster, " . $_POST['forum'] . ")"); //Line 316
  21.     $result2 = $mysqli->query("INSERT INTO threads (forum, title, posted, poster, views, posts, lastposttime) VALUES (" . $_POST['forum'] . ", " . $_POST['subject'] . ", $posted, $poster, 1, 0, $posted)");
  22.     $thread = $mysqli->query("SELECT id FROM threads WHERE title='$title' AND forum=" . $_POST['forum'] . " AND posted=$posted AND poster=$poster")->fetch_row();
  23.     $post = $mysqli->query("SELECT id FROM posts WHERE posted=$posted AND poster=" . $_SESSION['user'] . " AND forum=" . $_POST['forum'])->fetch_row();
  24.     $result3 = $mysqli->query("UPDATE posts SET thread=" . $thread[0] . " WHERE id=" . $post[0]);
  25.     if ($result && $result2 && $result3) {
  26.         echo "Your post has been created.<br /><br />";
  27.         $res = $mysqli->query("SELECT id FROM posts WHERE posted=$posted AND thread=" . $_POST['thread'] . " AND poster=$poster")->fetch_row();
  28.         echo "<a href='forums.php?thread=" . $_POST['thread'] . "#post" . $res[0] . ">Click here</a> to go to your post.<br />";
  29.         echo "<a href='forums.php?thread=" . $_POST['thread'] . ">Click here</a> to return to the previous thread.";
  30.     } else {
  31.         $mysqli->query("DELETE FROM posts WHERE posted=$posted AND poster=$poster AND forum=" . $_POST['forum']);
  32.         $mysqli->query("DELETE FROM threads WHERE forum=" . $_POST['forum'] . " AND title=" . $_POST['subject'] . " AND posted=$posted AND poster=$poster");
  33.         echo "Error creating post: " . $mysqli->error . "<br /><br />";
  34.         echo "<a href='forums.php?thread=" . $_POST['thread'] . ">Click here</a> to return to the previous thread.";
  35.     }
  36. }
  37.  
  38. Output:
  39.  
  40. Notice: Undefined index: forum in /home/tristan/Website/Instart/forums.php on line 316 Notice: Undefined index: forum in /home/tristan/Website/Instart/forums.php on line 317 Notice: Undefined index: forum in /home/tristan/Website/Instart/forums.php on line 318 Fatal error: Call to a member function fetch_row() on a non-object in /home/tristan/Website/Instart/forums.php on line 318
  41.  
  42. Content of the comment (filled with a print_r):
  43.  
  44. <!-- Variables: Array
  45. (
  46.     [subject] => Next milestone.
  47.     [content] => This is the first thread created through the website, rather than through the database.
  48.     [newthread] => Post
  49. )
  50. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement