Guest User

Untitled

a guest
Feb 25th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>SQLdatabase</title>
  6. </head>
  7.  
  8. <body>
  9.  
  10.  
  11.  
  12.  
  13. <?php
  14.  
  15. if($_SERVER["REQUEST_METHOD"] == "POST") {
  16.  
  17. //retrieve values from the form
  18. $firstname = $_POST["firstname"];
  19. $surname = $_POST["surname"];
  20. $email = $_POST["email"];
  21.  
  22.  
  23.  
  24. //connect to mysql database
  25. $servername = "mysql11.000webhost.com";
  26. $username = "a3245379_Ligeris";
  27. $password = "yehoshua1";
  28. $dbname = "a3245379_Ligeris";
  29.  
  30. //create connection
  31. $conn = new MySQLi($servername, $username, $password, $dbname);
  32.  
  33. //check connection
  34. if ($conn->connect_error) {//if error stop loading html and display error
  35. die("Connection failed: " . $conn->connect_error);
  36. }
  37.  
  38. //create SQL INSERT INTO query
  39. $sql = "INSERT INTO MyGuests (firstname, lastname, email)
  40. VALUES ('".$firstname."', '".$surname."', '".$email."')";
  41.  
  42.  
  43.  
  44. if ($conn->query($sql) === TRUE) {//send query to database table and check result
  45. echo "New record created successfully";
  46. } else {
  47. echo "Error: " . $sql . "<br>" . $conn->error;
  48. }
  49.  
  50. $conn->close();//close database connection
  51. }
  52.  
  53. ?>
  54.  
  55.  
  56. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  57. <p>Firstname
  58. <label for="firstname"></label>
  59. <input type="text" name="firstname" id="firstname" />
  60. </p>
  61. <p>Surname
  62. <input type="text" name="surname" id="surname" />
  63. </p>
  64. <p>Email
  65. <input type="text" name="email" id="email" />
  66. </p>
  67. <input type="submit" name="submit" value="Submit" />
  68. </form>
  69.  
  70. </body>
  71. </html>
Add Comment
Please, Sign In to add comment