Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <?php
  2. include_once("scripts/connect.php");
  3. $name=strip_tags($_POST['name']);
  4. $comment=strip_tags($_POST['comment']);
  5. $submit=strip_tags($_POST['submit']);
  6.  
  7. if($submit)
  8. {
  9. if(trim($name) == "" || trim($comment) == "" )
  10. {
  11. echo "Please fill out all field";
  12. }
  13. $cQuery = $db->prepare("INSERT INTO CommentBox (name,comment) VALUES (:name ,:comment) ");
  14. $cQuery->bindValue(':name',$name,PDO::PARAM_STR);
  15. $cQuery->bindValue(':comment',$comment,PDO::PARAM_STR);
  16. try{
  17. $cQuery->execute();
  18. header("location: post.php");
  19. }
  20. catch(PDOException $e){
  21. echo $e->getMessage();
  22. $db = null;
  23. exit();
  24. }
  25.  
  26. }
  27. ?>
  28.  
  29. <html>
  30. <head>
  31. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  32. <title>Comment box</title>
  33. </head>
  34.  
  35. <body>
  36. <center>
  37. <form action="post.php" method="POST">
  38. <table>
  39. <tr><td>Name: <br><input type="text" name="name"/></td></tr>
  40. <tr><td colspan="2">Comment: </td></tr>
  41. <tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea></td></tr>
  42. <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
  43. </table>
  44. </form>
  45.  
  46. <?php
  47. include_once("scripts/connect.php");
  48.  
  49.  
  50. //$rows = $db->prepare("SELECT * FROM commenttable ORDER BY id DESC");
  51.  
  52. $rows = $db->query("SELECT * FROM CommentBox ORDER BY id DESC");
  53. while($rows->fetch(PDO::FETCH_ASSOC))
  54. {
  55. $id=$rows['id'];
  56. $name=$rows['name'];
  57. $comment=$rows['comment'];
  58. echo $name . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="1"/>'. "\n";
  59. }
  60.  
  61. ?>
  62.  
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement