Advertisement
Guest User

Untitled

a guest
Nov 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 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. $post_comment = $conn -> prepare("INSERT INTO `comments` (content)
  53. VALUES (:comment_content)");
  54.  
  55. $post_comment -> bindParam(":comment_content", $comment_content);
  56. $post_comment -> execute();
  57. echo "Comment has been posted.";
  58. }
  59.  
  60. if(isset($_POST["submit_message"])) {
  61. //Message section
  62. $message_content = $_POST['message'];
  63.  
  64. $send_message = $conn -> prepare("INSERT INTO `messages` (content)
  65. VALUES (:message_content)");
  66.  
  67.  
  68. $send_message -> bindParam(":message_content", $message_content);
  69. $send_message -> execute();
  70. echo "Message has been sent.";
  71. }
  72. }
  73.  
  74. catch(PDOException $e) {
  75. echo "Connection failed: " . $e->getMessage();
  76. }
  77.  
  78. ?>
  79.  
  80. <form method="post">
  81. <label>First name:</label>
  82. <input type="text" name="first_name" placeholder="First Name">
  83.  
  84.  
  85. <label>Last name:</label>
  86. <input type="text" name="last_name" placeholder="LastName">
  87.  
  88. <label>Alias:</label>
  89. <input type="text" name="alias" placeholder="Alias">
  90.  
  91. <label>Description:</label>
  92. <input type="text" name="description" placeholder="Description">
  93.  
  94. <label>Age:</label>
  95. <input type="number" name="age" placeholder="Age">
  96.  
  97. <label>Location:</label>
  98. <input type="text" name="location" placeholder="Location">
  99.  
  100. <label>Occupation:</label>
  101. <input type="text" name="occupation" placeholder="Occupation">
  102.  
  103. <label>Super powers:</label>
  104. <input type="text" name="power" placeholder="Powers">
  105.  
  106. <label>Arch-enemy:</label>
  107. <input type="text" name="arch_enemy" placeholder="Arch-enemy">
  108.  
  109. <input type="submit" name="submit" value="SAVE CHANGES">
  110. </form>
  111.  
  112. <?php
  113. $stmt = $conn->query('SELECT content, time, sender FROM comments');
  114. foreach ($stmt as $row) {
  115. echo $row['content'];
  116. echo $row['time'];
  117. echo $row['sender'];
  118. ?>
  119. </br>
  120. <?php
  121. }
  122. ?>
  123. <form method="post">
  124. <label>Comment:</label>
  125. <textarea name="comment" placeholder="Your comment"></textarea>
  126.  
  127. <input type="submit" name="submit_comment" value="POST">
  128. </form>
  129.  
  130.  
  131. <?php
  132. $stmt = $conn->query('SELECT content, time, sender FROM messages');
  133. foreach ($stmt as $row) {
  134. echo $row['content'];
  135. echo $row['time'];
  136. echo $row['sender'];
  137. ?>
  138. </br>
  139. <?php
  140. }
  141. ?>
  142. <form method="post">
  143. <label>Message:</label>
  144. <textarea name="message" placeholder="Your comment"></textarea>
  145.  
  146. <input type="submit" name="submit_message" value="MESSAGE">
  147. </form>
  148.  
  149.  
  150. </body>
  151. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement