I am taking simple user data from HTML page and inserting it into a database. But it is not working. When I click the submit button it redirect to submit.php page and shows the submit code. Where is the error? Here is my code.
HTML code:
<!DOCTYPE html>
<html>
<head>
<title>
Databse connection
</title>
</head>
<body>
<form action="submit.php" method="POST">
<table>
<tr>
<td>
Name:
</td>
<td>
<input type="text" name="username">
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="submit">
</td>
</tr>
</table>
</form>
</body>
</html>
And PHP code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Create database
$sql = "CREATE DATABASE myDB";
$conn->query($sql);
// sql to create table
$sql = "CREATE TABLE usertable (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(30) NOT NULL)";
$conn->query($sql);
// insert data
// static data for test purpose
$sql = "INSERT INTO usertable (username) VALUES ("firstuser")";
$conn->query($sql);
// close connection
$conn->close();
?>