Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once("scripts/connect.php");
- $name=strip_tags($_POST['name']);
- $comment=strip_tags($_POST['comment']);
- $submit=strip_tags($_POST['submit']);
- if($submit)
- {
- if(trim($name) == "" || trim($comment) == "" )
- {
- echo "Please fill out all field";
- }
- $cQuery = $db->prepare("INSERT INTO CommentBox (name,comment) VALUES (:name ,:comment) ");
- $cQuery->bindValue(':name',$name,PDO::PARAM_STR);
- $cQuery->bindValue(':comment',$comment,PDO::PARAM_STR);
- try{
- $cQuery->execute();
- header("location: post.php");
- }
- catch(PDOException $e){
- echo $e->getMessage();
- $db = null;
- exit();
- }
- }
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Comment box</title>
- </head>
- <body>
- <center>
- <form action="post.php" method="POST">
- <table>
- <tr><td>Name: <br><input type="text" name="name"/></td></tr>
- <tr><td colspan="2">Comment: </td></tr>
- <tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea></td></tr>
- <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
- </table>
- </form>
- <?php
- include_once("scripts/connect.php");
- //$rows = $db->prepare("SELECT * FROM commenttable ORDER BY id DESC");
- $rows = $db->query("SELECT * FROM CommentBox ORDER BY id DESC");
- while($rows->fetch(PDO::FETCH_ASSOC))
- {
- $id=$rows['id'];
- $name=$rows['name'];
- $comment=$rows['comment'];
- echo $name . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="1"/>'. "\n";
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement