Guest User

Untitled

a guest
Feb 18th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <!-- this is index.php page -->
  2. <!DOCTYPE html>
  3. <html lang="en">
  4. <head>
  5. <meta charset="UTF-8">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <form action="insert.php" method="post">
  10. Name: <input type="text" name="username" /> <br />
  11. E-mail: <input type="text" name="email" /> <br />
  12. <input type="submit" value="Submit" name="submit" />
  13. </form>
  14. </body>
  15. </html>
  16.  
  17.  
  18.  
  19.  
  20. // this is insert.php page
  21. <?php
  22.  
  23. $servername = "localhost";
  24. $username = "root";
  25. $password = "";
  26. $dbname = "tutorial";
  27.  
  28. // Create connection
  29. $conn = mysqli_connect($servername, $username, $password, $dbname);
  30. // Check connection
  31. if (!$conn) {
  32. die("Connection failed: " . mysqli_connect_error());
  33. }
  34.  
  35. $username = $_POST['username'];
  36. $email = $_POST['email'];
  37.  
  38. $sql = "INSERT INTO PERSON (Name, Email) VALUES ('$username', '$email')";
  39.  
  40. if (mysqli_query($conn, $sql)) {
  41. echo "New record created successfully";
  42. } else {
  43. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  44. }
  45.  
  46. mysqli_close($conn);
  47. ?>
Add Comment
Please, Sign In to add comment