Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <title>form practice</title>
  8.  
  9. </head>
  10.  
  11. <body>
  12.  
  13. <div class="form2" id="form2" name="form2">
  14.  
  15. <form action="php/form2.php" method="post" id="Personalinfo">
  16.  
  17. <label for="fname">Name:</label>
  18. <input type="text" id="fname" name="firstname" placeholder="Client
  19. Name..">
  20.  
  21. <label for="lname">Lastname:</label>
  22. <input type="text" id="lname" name="lastname" placeholder="Client
  23. Lastname..">
  24.  
  25. <label for="dob">Birthday:</label>
  26. <input type="text" id="dob" name="dob" placeholder="yyyy/mm/dd..">
  27.  
  28. <label for="age">Age:</label>
  29. <input type="text" id="age" name="age" placeholder="Client Age..">
  30.  
  31. <input type="submit" name="submitForm2" value="Submit">
  32.  
  33.  
  34. </form>
  35. </div>
  36.  
  37. </body>
  38. </html>
  39.  
  40. <?php
  41. $servername = "localhost";
  42. $username = "root";
  43. $password = "";
  44. $dbname = "testdb";
  45.  
  46. // Create connection
  47. $conn = new mysqli($servername, $username, $password, $dbname);
  48. // Check connection
  49. if ($conn->connect_error) {
  50. die("Connection failed: " . $conn->connect_error);
  51. }
  52.  
  53. if(isset($_POST['submitForm2'])){
  54. $firstname = $_POST['firstname'];
  55. $lastname = $_POST['lastname'];
  56. $dob = $_POST['dob'];
  57. $age = $_POST['age'];
  58.  
  59. $sql = "INSERT INTO info (firstname, lastname, dob, age)
  60. VALUES ('{$firstname}', '{$lastname}', '{$dob}', '{$age}')";
  61.  
  62. if ($conn->query($sql) === TRUE) {
  63. echo "New record created successfully";
  64. } else {
  65. echo "Error: " . $sql . "<br>" . $conn->error;
  66. }
  67.  
  68. }else{
  69. echo "Are you sure you enter a firstname and the name of your html submit
  70. is submitForm";
  71. }
  72.  
  73. $conn->close();
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement