I am trying to add a new user to a table. I've created the form, connected to the database and created the query. When I press the submit button it takes me to the next page but a new row isn't made and the data is lost. Note: Connection details are right, just changed to show you :). Also the tables User_ID column is set to auto increment. Please help. (I have looked at other similar questions but I still can't get it working)
<html>
<head>
</head>
<body>
<div>
<form action ="/Product.php" method="post">
<label><h1>Add User</h1></label><br>
<label>Username</label>
<input type="text" name="Username"><br>
<label>Password</label>
<input type="text" name="Password"><br>
<label>User type</label>
<select multiple>
<option value="Admin">Admin</option>
<option value="Registered user">Registered user</option>
<option value="Guest">Guest</option>
</select>
<input name="Submit" type="Submit"/><br>
</form>
</div>
<?php
$connection = mysqli_connect('host', 'username', 'password', 'database');
if (mysqli_connect_error()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else {
if(isset($_POST['Submit'])){
$Username=$_POST['Username'];
$Password=$_POST['Password'];
$User_Type=$_POST['User_Type'];
$query = "INSERT INTO Login (User_ID, Username, Password, User_Type) VALUES('','$Username','$Password','$User_Type')";
$result = mysqli_query($query);
}
}
?>
</body>
</html>