Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>insert data in database using mysqli</title>
  4.  
  5. </head>
  6. <body>
  7.  
  8. <div id="main">
  9. <h1>Insert data into database using mysqli</h1>
  10. <div id="login">
  11. <h2>Friends Form</h2>
  12. <hr/>
  13. <form action="" method="post">
  14. <label>ID :</label>
  15. <input type="text" name="id" id="id"><br /><br />
  16. <label>firstname :</label>
  17. <input type="text" name="firstname" id="firstname"><br/><br />
  18. <label>lastname :</label>
  19. <input type="text" name="lastname" id="lastname"><br/><br/>
  20.  
  21. <label>email :</label>
  22. <input type="text" name="email" id="email"><br/><br/>
  23.  
  24. <input type="submit" value=" Submit " name="submit"/><br />
  25. </form>
  26. </div>
  27.  
  28. <?php
  29. if(isset($_POST["submit"])){
  30. $servername = "localhost";
  31. $username = "amal";
  32. $password = "amal";
  33. $dbname = "myamal";
  34.  
  35. // Create connection
  36. $conn = new mysqli($servername, $username, $password, $dbname);
  37. // Check connection
  38. if ($conn->connect_error) {
  39. die("Connection failed: " . $conn->connect_error);
  40. }
  41. $sql = "INSERT INTO myfriends (id,firstname, lastname,email,reg_date)
  42. VALUES ('".$_POST["id"]."','".$_POST["firstname"]."', '".$_POST["lastname"]."','".$_POST["email"]."',CURRENT_TIMESTAMP);";
  43.  
  44. if ($conn->query($sql) === TRUE) {
  45. echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
  46. } else {
  47. echo "<script type= 'text/javascript'>alert('Error: insert failed');</script>";
  48. }
  49.  
  50. $conn->close();
  51. }
  52. ?>
  53. </body>
  54. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement