Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4.  
  5. </head>
  6.  
  7. <body>
  8.  
  9. <ul>
  10.  
  11. <li style="float:left"><b>Reddit</b></li><br>
  12.  
  13. <li><a href="recent.php">recent</a></li>
  14.  
  15. <li><a href="hot.php">hot</a></li>
  16.  
  17. </ul>
  18. <!-- navigation bar -->
  19.  
  20. <form method='POST'>
  21. Username: <input type="text" name="username"/><br>
  22. Password: <input type="text" name="password"/>
  23. <input type="submit">
  24. </form>
  25.  
  26.  
  27.  
  28. <?php
  29.  
  30. $username = $_POST['username'];
  31. $password = $_POST['password'];
  32.  
  33. $db = new PDO('mysql:host=localhost;dbname=newsit', 'root', 'root');
  34.  
  35. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  36. //ensure error messgae occurs when there is one
  37.  
  38. $loginQuery = $db->prepare('SELECT COUNT(*) AS userCount FROM `users` WHERE username = ? AND password = ?');
  39. $loginQuery->execute([$username, $password]);
  40.  
  41. if ($loginQuery->fetchColumn() == 1) {
  42. echo "oh hello there";
  43. } else {
  44. echo "NO";
  45. }
  46.  
  47. echo '<br>';
  48.  
  49. $recent = $db->query('SELECT * FROM `posts` INNER JOIN users ON posts.userID = users.id ORDER BY `posts`.`postDate` DESC');
  50. $recent->execute();
  51.  
  52. foreach($recent as $row) {
  53.  
  54. $url = $row["postURL"];
  55. echo '<b>' . $row['username'].': ';
  56. echo '</b>';
  57. echo '<a href=';
  58. echo '"'.$url. '"';
  59. echo '>';
  60. echo $row["postTitle"];
  61. echo '</a>';
  62. echo '<br>';
  63. echo '<br>';
  64.  
  65. $url = $row["postURL"];
  66.  
  67.  
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. ?>
  76.  
  77. </body>
  78.  
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement