Created
August 12, 2014 14:44
-
-
Save samroar/3ed734c2a0bd7437402e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <?php | |
| $dbh = new PDO('mysql:dbname=reddit;host:localhost', 'root', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING)); | |
| if(!empty($_POST)) { | |
| $query = $dbh->prepare('INSERT INTO comments (post, user, body) VALUES (?, ?, ?)'); | |
| $query->execute(array($_POST['post'], '', $_POST['body'])); | |
| header("Location: " . "http://" . $_SERVER['HTTP_HOST'] . "/reddit/post.php"); | |
| } | |
| ?> | |
| <html> | |
| <head> | |
| <title>reddit: the front page of the internet</title> | |
| <link href="reddit.css" rel="stylesheet"/> | |
| <script src="reddit.js" type="text/javascript"></script> | |
| </head> | |
| <body> | |
| <?php | |
| if(!empty($_GET)) { | |
| $rows = $dbh->prepare("SELECT id, title, user, subreddit, url, timestamp FROM posts WHERE id = ?"); | |
| $rows->execute(array($_GET['id'])); | |
| foreach($rows as $row) { ?> | |
| <div class="container"> | |
| <h2 class="title"> | |
| <a href="http://localhost/reddit/post.php?id=<?php echo $row['id']; ?>"> <?php echo $row['title']; ?></a> | |
| </h2> | |
| <div class="info"> | |
| submitted <?php echo $row['timestamp']; ?> by <?php echo $row['user']; ?> to <?php echo $row['subreddit']; ?> | |
| </div> | |
| </div> | |
| <?php } | |
| } | |
| ?> | |
| <form action="post.php" method="POST"> | |
| <label>Post<input type="text" name="post" /></label> | |
| <label>Body<input type="text" name="body" /></label> | |
| <input type="submit"> | |
| </form> | |
| <?php | |
| if(!empty($_GET)) { | |
| $comments = $dbh->prepare("SELECT id, user, timestamp, post, body FROM comments WHERE id = ?"); | |
| $comments->execute(array($_GET['id'])); | |
| foreach($comments as $comment) { ?> | |
| <div class="box"> | |
| <div class="information"> | |
| <?php echo $comment['user']; ?> <?php echo $comment['timestamp']; ?>ago | |
| </div> | |
| <div class="comment"> | |
| <?php echo $comment['body']; ?> | |
| </div> | |
| <?php } | |
| } | |
| ?> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment