Advertisement
Guest User

Untitled

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