Guest User

Untitled

a guest
Dec 25th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $username = $_SESSION['name'];
  5.  
  6. $db = pg_connect("host=127.0.0.1 dbname=Verkefni5a user=postgres password=xxxxx");
  7. $result = pg_query($db, "SELECT m.timestamp, message
  8. FROM messages m, users u
  9. WHERE username='" . $username . "' AND m.userid=u.id
  10. ORDER BY m.timestamp DESC LIMIT 5");
  11.  
  12. $friend_result = pg_query($db, "Select username, timestamp, message
  13. FROM users INNER JOIN
  14. (
  15. (SELECT userid, timestamp, message
  16. FROM messages INNER JOIN
  17. (
  18. SELECT following
  19. FROM follows
  20. WHERE userid =
  21. (SELECT id from users
  22. WHERE username = '" . $username . "')
  23. ) AS foo
  24. ON messages.userid=foo.following)
  25. ) AS foo2
  26. ON users.id = foo2.userid
  27. ORDER BY timestamp DESC LIMIT 20");
  28.  
  29. ?>
  30. <html>
  31. <head>
  32. <title>Welcome<?php echo " " . $username . "!"; ?></title>
  33. </head>
  34. <body>
  35. <?php
  36. echo "<h1>Welcome " . $username . "!</h1>\n";
  37. echo "Your latest posts:<br>";
  38. echo "<table border=\"1\" cellpaddin=\"2\" cellspacing=\"2\">";
  39. echo "<tr>";
  40. echo "<td>Date and time</td>";
  41. echo "<td>Messages</td>";
  42. echo "</tr>";
  43. while ($row = pg_fetch_assoc($result))
  44. {
  45. print '<tr>';
  46. print '<td>' . $row['timestamp'] . '</td>';
  47. print '<td>' . $row['message'] . '</td>';
  48. print '</tr>';
  49. }
  50. echo "</table>";
  51. ?>
  52. <br /><b>Have something to say?</b><br />
  53. <form name="input" action="update.php" method="POST">
  54. <label>Message: </label><input type="text" name="update" />
  55. <input type="submit" value="Submit" />
  56. </form>
  57.  
  58. <br /><b>Want to see what someone else is saying? Write his/her name here!</b><br />
  59. <form name="input" action="view.php" method="GET">
  60. <label>Username: </label><input type="text" name="username" />
  61. <input type="submit" value="Submit" />
  62. </form>
  63.  
  64. <br /><b>Those that you are following are saying this: </b><br />
  65.  
  66. <?php
  67. echo "<table border=\"1\" cellpaddin=\"2\" cellspacing=\"2\">";
  68. echo "<tr>";
  69. echo "<td>Username</td>";
  70. echo "<td>Messages</td>";
  71. echo "<td>Date and time</td>";
  72. echo "</tr>";
  73. while ($row = pg_fetch_assoc($friend_result))
  74. {
  75. print '<tr>';
  76. print '<td>' . $row['username'] . '</td>';
  77. print '<td>' . $row['message'] . '</td>';
  78. print '<td>' . $row['timestamp'] . '</td>';
  79. print '</tr>';
  80. }
  81. echo "</table>";
  82. ?>
  83. <p />Log out:<input type="button" onclick="self.location='logout.php'" value="HERE!" />
  84.  
  85. </body>
  86. </html>
  87. }
  88. else
Add Comment
Please, Sign In to add comment