Advertisement
Guest User

Untitled

a guest
Nov 16th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Super Dating</title>
  5. <link rel="stylesheet" type="text/css" href="style.css">
  6. </head>
  7. <body>
  8.  
  9. <?php
  10. $servername = "localhost";
  11. $username = "root";
  12. $password = "";
  13.  
  14. try {
  15. $conn = new PDO("mysql:host=$servername;dbname=super_dating", $username, $password);
  16. // set the PDO error mode to exception
  17. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18. echo "Connected successfully";
  19.  
  20. if(isset($_POST["submit"])) {
  21.  
  22. //Editing profile settings
  23. $first_name = $_POST['first_name'];
  24. $last_name = $_POST['last_name'];
  25. $alias = $_POST['alias'];
  26. $description = $_POST['description'];
  27. $age = $_POST['age'];
  28. $location = $_POST['location'];
  29. $occupation = $_POST['occupation'];
  30. $power = $_POST['power'];
  31. $arch_enemy = $_POST['arch_enemy'];
  32.  
  33. $insert = $conn->prepare("UPDATE `profile` SET first_name = '$first_name',
  34. last_name = '$last_name',
  35. alias = '$alias',
  36. description = '$description',
  37. age = '$age',
  38. location = '$location',
  39. occupation = '$occupation',
  40. power = '$power',
  41. arch_enemy = '$arch_enemy'
  42. WHERE id = '1'");
  43.  
  44. $insert->execute();
  45. echo "Changes saved.";
  46. }
  47.  
  48. if(isset($_POST["submit_comment"])) {
  49. //Comments section
  50. $comment_content = $_POST['comment'];
  51.  
  52. $insert_recipient = $conn -> prepare("INSERT INTO `comments` (recipient)
  53. SELECT alias
  54. FROM profile
  55. WHERE id = 1;
  56. INSERT INTO `comments` (content)
  57. VALUES (:comment_content);"
  58.  
  59. $insert_recipient -> execute();
  60.  
  61. $post_comment = $conn -> prepare("INSERT INTO `comments` (content)
  62. VALUES (:comment_content)");
  63.  
  64. $post_comment -> bindParam(":comment_content", $comment_content);
  65. $post_comment -> execute();
  66. echo "Comment has been posted.";
  67. }
  68.  
  69. if(isset($_POST["submit_message"])) {
  70. //Message section
  71. $message_content = $_POST['message'];
  72.  
  73. $send_message = $conn -> prepare("INSERT INTO `messages` (content)
  74. VALUES (:message_content)");
  75.  
  76.  
  77. $send_message -> bindParam(":message_content", $message_content);
  78. $send_message -> execute();
  79. echo "Message has been sent.";
  80. }
  81. }
  82.  
  83. catch(PDOException $e) {
  84. echo "Connection failed: " . $e->getMessage();
  85. }
  86.  
  87. ?>
  88.  
  89. <form method="post">
  90. <label>First name:</label>
  91. <input type="text" name="first_name" placeholder="First Name">
  92.  
  93.  
  94. <label>Last name:</label>
  95. <input type="text" name="last_name" placeholder="LastName">
  96.  
  97. <label>Alias:</label>
  98. <input type="text" name="alias" placeholder="Alias">
  99.  
  100. <label>Description:</label>
  101. <input type="text" name="description" placeholder="Description">
  102.  
  103. <label>Age:</label>
  104. <input type="number" name="age" placeholder="Age">
  105.  
  106. <label>Location:</label>
  107. <input type="text" name="location" placeholder="Location">
  108.  
  109. <label>Occupation:</label>
  110. <input type="text" name="occupation" placeholder="Occupation">
  111.  
  112. <label>Super powers:</label>
  113. <input type="text" name="power" placeholder="Powers">
  114.  
  115. <label>Arch-enemy:</label>
  116. <input type="text" name="arch_enemy" placeholder="Arch-enemy">
  117.  
  118. <input type="submit" name="submit" value="SAVE CHANGES">
  119. </form>
  120.  
  121. <?php
  122. $stmt = $conn->query('SELECT content, time, sender, recipient FROM comments');
  123. foreach ($stmt as $row) {
  124. echo $row['content'];
  125. echo $row['time'];
  126. echo $row['sender'];
  127. echo $row['recipient'];
  128. ?>
  129. </br>
  130. <?php
  131. }
  132. ?>
  133. <form method="post">
  134. <label>Comment:</label>
  135. <textarea name="comment" placeholder="Your comment"></textarea>
  136.  
  137. <input type="submit" name="submit_comment" value="POST">
  138. </form>
  139.  
  140.  
  141. <?php
  142. $stmt = $conn->query('SELECT content, time, sender FROM messages');
  143. foreach ($stmt as $row) {
  144. echo $row['content'];
  145. echo $row['time'];
  146. echo $row['sender'];
  147. ?>
  148. </br>
  149. <?php
  150. }
  151. ?>
  152. <form method="post">
  153. <label>Message:</label>
  154. <textarea name="message" placeholder="Your comment"></textarea>
  155.  
  156. <input type="submit" name="submit_message" value="MESSAGE">
  157. </form>
  158.  
  159.  
  160. </body>
  161. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement