Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. <?php
  2. $serverName = 'localhost'; //Variables to access the database
  3. $username = 'root';
  4. $password = '';
  5. $database = 'snake_database';
  6. $moderator = 0;
  7.  
  8. $conn = mysqli_connect($serverName, $username, $password, $database); //Connect to the database
  9.  
  10. if (!empty($_SESSION["loggedUser"])) //If someone is logged in
  11. {
  12. $moderator = $_SESSION["loggedUser"][2]; //Check if they are a moderator
  13. }
  14.  
  15. if(!$conn) //If the database failed to connect
  16. {
  17. die("Database failed to connect: " .mysqli_connect_error()); //Display an error message
  18. }
  19.  
  20. $sql = "SELECT * FROM posts ORDER BY `posts`.`date` DESC"; //Select all posts, latest first
  21. $stmt = $conn->prepare($sql);
  22. $stmt->execute(); //Execute the query
  23.  
  24. $result = $stmt->get_result();
  25. $count = mysqli_num_rows($result);
  26.  
  27. if ($count > 0) //If there is more than one post
  28. {
  29. while($row = $result->fetch_assoc()) //For every post, display each one
  30. { ?>
  31. <div class="post">
  32. <div class="post-header">
  33. <h3><?php echo $row["username"]; ?></h3> <!-- Display their username -->
  34. </div>
  35.  
  36. <form action="functions/directProfile.php" method="get" accept-charset="utf-8"> <!-- Display their profile picture as a link to their profile page -->
  37. <input type="hidden" name="user" value="<?php echo htmlspecialchars($row["username"]); ?>" >
  38. <input type="submit" value="" class="post-image" class="submit-button" style="background-image: url('graphics/buttons/profile.png');">
  39. </form>
  40.  
  41. <textarea class="post-message" readonly="readonly"><?php echo $row["post"] . " - " . $row["date"] . "&#10;Likes: " . $row["votes_up"] . " Dislikes: " . $row["votes_down"]; ?></textarea>
  42.  
  43. <?php
  44. $postId = $row["post_id"]; //Get the post_id and user_id
  45. $userId = $row["user_id"];
  46.  
  47. if ($moderator == 1) //Show these buttons only if they
  48. { ?>
  49. <form action="functions/muteUser.php" method="post" accept-charset="utf-8"> <!-- Form for the mute/ unmute user button -->
  50. <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" > <!-- Make a hidden input with the posts id so i can retrieve it in muteUser.php -->
  51.  
  52. <?php
  53. $sqlM = "SELECT * FROM `users` WHERE user_id = ?"; //Get the users info who posted this post
  54. $stmtM = $conn->prepare($sqlM);
  55. $stmtM->bind_param("i", $userId); //bind user id as an integer
  56. $stmtM->execute(); //Execute the query
  57.  
  58. $resultM = $stmtM->get_result(); //Get the results
  59. $rowM = $resultM->fetch_assoc();
  60.  
  61. if ($rowM["muted"] == 1) //If the user is already muted, display a muted button
  62. { ?>
  63. <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/muteon.png');"><?php
  64. } else //If not, display a button to show they arnt muted
  65. { ?>
  66. <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/muteoff.png');"><?php
  67. } ?>
  68. </form>
  69.  
  70. <form action="functions/deletePost.php" method="post" accept-charset="utf-8"> <!-- Button to delete post -->
  71. <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" >
  72. <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/delete.png');">
  73. </form><?php
  74. } ?>
  75.  
  76. <form action="functions/voteUp.php" method="post" accept-charset="utf-8"> <!-- Button to up vote this post -->
  77. <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" >
  78. <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/voteupoff.png');">
  79. </form>
  80.  
  81. <form action="functions/voteDown.php" method="post" accept-charset="utf-8"> <!-- Button to down vote this post -->
  82. <input type="hidden" name="postId" value="<?php echo htmlspecialchars($postId); ?>" >
  83. <input type="submit" value="" class="post-buttons" style="background-image: url('graphics/buttons/votedownoff.png');">
  84. </form>
  85. </div><?php
  86. }
  87. }
  88.  
  89. $stmt->close(); //Close the statment and connection
  90. $conn->close();
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement