Advertisement
Guest User

Untitled

a guest
Oct 30th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. <!doctype html>
  2.  
  3. <meta charset="UTF-8">
  4. <meta name="author" content="Ricky">
  5. <meta name="keywords" content="SQL Database">
  6.  
  7. <title>Database Queries</title>
  8.  
  9. <link rel="stylesheet" href="styles.css">
  10.  
  11. <?php
  12. $servername = "localhost";
  13. $username = "root";
  14. $password = "";
  15. $dbname = "OC14062";
  16.  
  17. if(!empty($_POST["Name"])){
  18. $htmlName = $_POST["Name"];
  19. $htmlPosition = $_POST["Position"];
  20. $htmlAddress = $_POST["Address"];
  21. $htmlDoB = $_POST["DoB"];
  22. $htmlPhoneNumber = $_POST["PhoneNumber"];
  23. $htmlScubaTank = $_POST["ScubaTank"];
  24. $htmlIroningBoard = $_POST["IroningBoard"];
  25. }
  26.  
  27. $serverConnection = new mysqli($servername, $username, $password, $dbname);
  28.  
  29. if($serverConnection->connect_error) {
  30. die("Connection failed: " . $serverConnection->connect_error);
  31. }
  32. ?>
  33.  
  34. <header>
  35. <h1>Underwater Ironing Club</h1>
  36.  
  37. <nav>
  38. <a href="ironing.html">Update</a>
  39. <a href="">Display</a>
  40. </nav>
  41. </header>
  42.  
  43. <section>
  44. <?php
  45. if(!empty($_POST["Name"])){
  46.  
  47. $insertSQL = "INSERT INTO UnderwaterIroningClub (Name, Position, Address, DoB, PhoneNumber, ScubaTank, IroningBoard) VALUES ('$htmlName', '$htmlPosition', '$htmlAddress', '$htmlDoB', '$htmlPhoneNumber', '$htmlScubaTank', '$htmlIroningBoard')";
  48.  
  49. if ($serverConnection->query($insertSQL) === TRUE) {
  50. echo "New record created successfully <br><br>";
  51. } else {
  52. echo "Error: " . $insertSQL . "<br>" . $serverConnection->error;
  53. }
  54. }
  55.  
  56. $selectSQL = "SELECT * FROM UnderwaterIroningClub";
  57.  
  58. $result = $serverConnection->query($selectSQL);
  59.  
  60. if ($result->num_rows > 0) {
  61. while($row = $result->fetch_assoc()) {
  62. echo "ID: " . $row["ID"] . "<br>";
  63. echo "Name: " . $row["Name"] . "<br>";
  64. echo "Position: " . $row["Position"] . "<br>";
  65. echo "Address: " . $row["Address"] . "<br>";
  66. echo "Date of birth: " . $row["DoB"] . "<br>";
  67. echo "Phone Number: " . $row["PhoneNumber"] . "<br>";
  68. echo "Scuba tank: " . $row["ScubaTank"] . "<br>";
  69. echo "Ironing board: " . $row["IroningBoard"] . "<br>";
  70. echo "<hr>";
  71. }
  72. } else {
  73. echo "Your table is empty.";
  74. }
  75.  
  76. $serverConnection->close();
  77. ?>
  78. </section>
  79.  
  80. <footer>
  81. &copy; Ricky Faulkner 2018
  82. </footer>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement