-1

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.

  • **Never store passwords in clear text or using MD5/SHA1!** Only store password hashes created using PHP's [`password_hash()`](https://php.net/manual/en/function.password-hash.php), which you can then verify using [`password_verify()`](https://php.net/manual/en/function.password-verify.php). Take a look at this post: [How to use password_hash](https://stackoverflow.com/q/30279321/1839439) and learn more about [bcrypt & password hashing in PHP](https://stackoverflow.com/a/6337021/1839439) – Dharman Jun 18 '20 at 16:16

1 Answers1

-2

Try echo $register; Copy that output and run at mysql to see result ;

Or $queryResult= $conn->query($register) Var_dump($queryResult)

To debug