Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>SQLdatabase</title>
- </head>
- <body>
- <?php
- if($_SERVER["REQUEST_METHOD"] == "POST") {
- //retrieve values from the form
- $firstname = $_POST["firstname"];
- $surname = $_POST["surname"];
- $email = $_POST["email"];
- //connect to mysql database
- $servername = "mysql11.000webhost.com";
- $username = "a3245379_Ligeris";
- $password = "yehoshua1";
- $dbname = "a3245379_Ligeris";
- //create connection
- $conn = new MySQLi($servername, $username, $password, $dbname);
- //check connection
- if ($conn->connect_error) {//if error stop loading html and display error
- die("Connection failed: " . $conn->connect_error);
- }
- //create SQL INSERT INTO query
- $sql = "INSERT INTO MyGuests (firstname, lastname, email)
- VALUES ('".$firstname."', '".$surname."', '".$email."')";
- if ($conn->query($sql) === TRUE) {//send query to database table and check result
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- $conn->close();//close database connection
- }
- ?>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- <p>Firstname
- <label for="firstname"></label>
- <input type="text" name="firstname" id="firstname" />
- </p>
- <p>Surname
- <input type="text" name="surname" id="surname" />
- </p>
- <p>Email
- <input type="text" name="email" id="email" />
- </p>
- <input type="submit" name="submit" value="Submit" />
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment