I have a registration form and after pressing the 'register' button, I'd like to check the database and see if that user already exists and if so return an error message "name already exists" and if it does not, of course, I'd like it to register the user. I found multiple other solutions that were asked before but nothing really worked. After many modifications the current code is this:
?php
if(isset($_POST['register'])) {
session_start();
$FName = $_POST['firstname'];
$LName = $_POST['lastname'];
$Email = $_POST['email'];
$PW = $_POST['password'];
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "users_db_physicians";
$conn = new mysqli($servername, $username, $password, $dbname);
$result_x = $conn->query("SELECT FROM users_database (username) WHERE username = '$Email'");
if (mysqli_num_rows($result_x)>=1) {
echo "name already exists";
}
else
{
$conn->query("INSERT INTO users_database (first_name, last_name, username, password)Values('{$FName}', '{$LName}', '{$Email}', '{$PW}')");
header('Location: login.php');
echo "it works";
}
}
?>
Now so far, with the above code, the only thing that happens is that the user gets registered (I checked the table and its updated) and the page moves to login.php so I am guessing the ELSE is working only and no row is generated or the if statement is buggy.
Please help.
appreciate your time, oliver_foxx