Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
86
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 lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Php form for MySQL</title>
  6. </head>
  7. <body>
  8. <form action="home.php" method="post">
  9. <p>
  10. <label for="table">Name your Table</label>
  11. <input type="text" name="table" id="table">
  12. </p>
  13. <p>
  14. <label for="firstName">First Name:</label>
  15. <input type="text" name="firstname" id="firstName">
  16. </p>
  17. <p>
  18. <label for="lastName">Last Name:</label>
  19. <input type="text" name="lastname" id="lastName">
  20. </p>
  21. <p>
  22. <label for="emailAddress">Email Address:</label>
  23. <input type="text" name="email" id="emailAddress">
  24. </p>
  25. <button name="submit" type="submit" value="submit">Create Table</button>
  26. </form>
  27.  
  28. if (isset($_POST['submit'])){
  29.  
  30. //enter database details
  31. $servername = "localhost";
  32. $username = "username";
  33. $password = "password";
  34. $dbname = "database";
  35.  
  36. // Create connection
  37. $conn = new mysqli($servername, $username, $password, $dbname);
  38. $tablename = $_POST['table'];
  39.  
  40. // Create a MySQL table in the selected database
  41. mysql_query("CREATE TABLE $table (
  42. firstname VARCHAR(30),
  43. lastname VARCHAR(30),
  44. email VARCHAR(50))") or die(mysql_error());
  45.  
  46. if ($conn->query($sql) === TRUE) {
  47. echo "Table account created successfully";
  48. } else {
  49. echo "Error creating table: " . $conn->error;
  50. }
  51.  
  52. // Check connection
  53. if ($conn->connect_error) {
  54. die("Connection failed: " . $conn->connect_error);
  55. }
  56.  
  57. $firstname = $_POST['firstname'];
  58. $lastname = $_POST['lastname'];
  59. $lemail = $_POST['email'];
  60.  
  61. if(isset($_POST['firstname']) || ($_POST['lastname']) || ($_POST['email']))
  62. {
  63. $order="INSERT INTO $table (firstname,lastname,email) VALUES ('$firstname','$lastname','$email')";
  64. $result = mysql_query($order) or die (mysql_error());
  65. }
  66.  
  67.  
  68. $conn->close();
  69. }
  70.  
  71. ?>
  72. </body>
  73. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement