Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Php form for MySQL</title>
- </head>
- <body>
- <form action="home.php" method="post">
- <p>
- <label for="table">Name your Table</label>
- <input type="text" name="table" id="table">
- </p>
- <p>
- <label for="firstName">First Name:</label>
- <input type="text" name="firstname" id="firstName">
- </p>
- <p>
- <label for="lastName">Last Name:</label>
- <input type="text" name="lastname" id="lastName">
- </p>
- <p>
- <label for="emailAddress">Email Address:</label>
- <input type="text" name="email" id="emailAddress">
- </p>
- <button name="submit" type="submit" value="submit">Create Table</button>
- </form>
- if (isset($_POST['submit'])){
- //enter database details
- $servername = "localhost";
- $username = "username";
- $password = "password";
- $dbname = "database";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- $tablename = $_POST['table'];
- // Create a MySQL table in the selected database
- mysql_query("CREATE TABLE $table (
- firstname VARCHAR(30),
- lastname VARCHAR(30),
- email VARCHAR(50))") or die(mysql_error());
- if ($conn->query($sql) === TRUE) {
- echo "Table account created successfully";
- } else {
- echo "Error creating table: " . $conn->error;
- }
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $firstname = $_POST['firstname'];
- $lastname = $_POST['lastname'];
- $lemail = $_POST['email'];
- if(isset($_POST['firstname']) || ($_POST['lastname']) || ($_POST['email']))
- {
- $order="INSERT INTO $table (firstname,lastname,email) VALUES ('$firstname','$lastname','$email')";
- $result = mysql_query($order) or die (mysql_error());
- }
- $conn->close();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement