Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- </head>
- <body>
- <ul>
- <li style="float:left"><b>Reddit</b></li><br>
- <li><a href="recent.php">recent</a></li>
- <li><a href="hot.php">hot</a></li>
- </ul>
- <!-- navigation bar -->
- <form method='POST'>
- Username: <input type="text" name="username"/><br>
- Password: <input type="text" name="password"/>
- <input type="submit">
- </form>
- <?php
- $username = $_POST['username'];
- $password = $_POST['password'];
- $db = new PDO('mysql:host=localhost;dbname=newsit', 'root', 'root');
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- //ensure error messgae occurs when there is one
- $loginQuery = $db->prepare('SELECT COUNT(*) AS userCount FROM `users` WHERE username = ? AND password = ?');
- $loginQuery->execute([$username, $password]);
- if ($loginQuery->fetchColumn() == 1) {
- echo "oh hello there";
- } else {
- echo "NO";
- }
- echo '<br>';
- $recent = $db->query('SELECT * FROM `posts` INNER JOIN users ON posts.userID = users.id ORDER BY `posts`.`postDate` DESC');
- $recent->execute();
- foreach($recent as $row) {
- $url = $row["postURL"];
- echo '<b>' . $row['username'].': ';
- echo '</b>';
- echo '<a href=';
- echo '"'.$url. '"';
- echo '>';
- echo $row["postTitle"];
- echo '</a>';
- echo '<br>';
- echo '<br>';
- $url = $row["postURL"];
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement