I have trouble inserting the users' email, name and password into the database. My database table has four columns 'id', 'email', 'name' and 'password'. 'id' is set as primary key and to auto-increment. But when I register a user, only the 'id' gets inserted but the other three columns are empty.
<h2>Register Here</h2>
<form action="registration.php">
<div class="form-group">
<label>Email</label>
<input type="text" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Username</label>
<input type="text" name="user" class="form-control" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
<?php
session_start();
header('Location: login.php');
$conn = mysqli_connect('localhost', 'root', '');
mysqli_select_db($conn, 'user_registration');
$email = $_POST['email'];
$name = $_POST['user'];
$password = $_POST['password'];
$select = "SELECT * FROM user_table WHERE name='$name'";
$result = mysqli_query($conn, $select);
$num = mysqli_num_rows($result);
if ($num == 1) {
echo "Username already taken.";
} else {
$register = "INSERT INTO user_table(email, name, password) VALUES ('$email', '$name', '$password')";
mysqli_query($conn, $register);
echo "Registration Successful.";
}
?>
The entry goes to the database, because an additional row gets added to the database, but except the 'id' field, everything is empty.
NOTE: I know the code is susceptible to SQL injection.