Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <meta charset="UTF-8">
- <meta name="author" content="Ricky">
- <meta name="keywords" content="SQL Database">
- <title>Database Queries</title>
- <link rel="stylesheet" href="styles.css">
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "OC14062";
- if(!empty($_POST["Name"])){
- $htmlName = $_POST["Name"];
- $htmlPosition = $_POST["Position"];
- $htmlAddress = $_POST["Address"];
- $htmlDoB = $_POST["DoB"];
- $htmlPhoneNumber = $_POST["PhoneNumber"];
- $htmlScubaTank = $_POST["ScubaTank"];
- $htmlIroningBoard = $_POST["IroningBoard"];
- }
- $serverConnection = new mysqli($servername, $username, $password, $dbname);
- if($serverConnection->connect_error) {
- die("Connection failed: " . $serverConnection->connect_error);
- }
- ?>
- <header>
- <h1>Underwater Ironing Club</h1>
- <nav>
- <a href="ironing.html">Update</a>
- <a href="">Display</a>
- </nav>
- </header>
- <section>
- <?php
- if(!empty($_POST["Name"])){
- $insertSQL = "INSERT INTO UnderwaterIroningClub (Name, Position, Address, DoB, PhoneNumber, ScubaTank, IroningBoard) VALUES ('$htmlName', '$htmlPosition', '$htmlAddress', '$htmlDoB', '$htmlPhoneNumber', '$htmlScubaTank', '$htmlIroningBoard')";
- if ($serverConnection->query($insertSQL) === TRUE) {
- echo "New record created successfully <br><br>";
- } else {
- echo "Error: " . $insertSQL . "<br>" . $serverConnection->error;
- }
- }
- $selectSQL = "SELECT * FROM UnderwaterIroningClub";
- $result = $serverConnection->query($selectSQL);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- echo "ID: " . $row["ID"] . "<br>";
- echo "Name: " . $row["Name"] . "<br>";
- echo "Position: " . $row["Position"] . "<br>";
- echo "Address: " . $row["Address"] . "<br>";
- echo "Date of birth: " . $row["DoB"] . "<br>";
- echo "Phone Number: " . $row["PhoneNumber"] . "<br>";
- echo "Scuba tank: " . $row["ScubaTank"] . "<br>";
- echo "Ironing board: " . $row["IroningBoard"] . "<br>";
- echo "<hr>";
- }
- } else {
- echo "Your table is empty.";
- }
- $serverConnection->close();
- ?>
- </section>
- <footer>
- © Ricky Faulkner 2018
- </footer>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement