Advertisement
Guest User

Untitled

a guest
Jul 5th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 3);
  3.  
  4. //Server-side variables
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "root";
  8. $database = "guestbook";
  9.  
  10. //HTML forms
  11. $postForm = file_get_contents("GuestBook Post.html");
  12. $viewForm = file_get_contents("GuestBook View.html");
  13.  
  14. // Create connection
  15. $conn = mysqli_connect($servername, $username, $password, $database, 8889);
  16.  
  17. // Check connection
  18. if ($conn->connect_error)
  19. {
  20. die("Connection failed: " . $conn->connect_error);
  21. }
  22. else
  23. {
  24. echo "Connected to MySQL database successfully!" . "\n";
  25.  
  26. //Get what the user typed in the HTML form (if it's not empty)
  27. if (!empty($_POST))
  28. {
  29. $postBtn = $_POST['Submit'];
  30. $name = $_POST['Name'];
  31. $email = $_POST['Email'];
  32. $website = $_POST['Website'];
  33. $comment = $_POST['Comment'];
  34.  
  35. //Send the data to a database-table with SQL query
  36. $query = "INSERT INTO `guests` (`Name`, `Email`, `Website`, `Comment`) VALUES ('{$name}', '{$email}', '{$website}', '{$comment}')";
  37. $result = mysqli_query($query, $conn) or die(mysqli_error());
  38. return $result;
  39.  
  40. //Text to display when sent
  41. echo "Post sent!" . "\n";
  42. }
  43. }
  44.  
  45. //Show HTML forms
  46. echo $postForm . "\n";
  47. echo $viewForm . "\n";
  48.  
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement