php registration issues


getting back into php after a long time so thanks for help

have this registration code…can’t get it to stop letting me register the same user over again
won’t kick it out if already registered
i know it is something simple thanks

[php]// If form submitted, insert values into the database.
if (isset($_REQUEST[‘username’])){
// removes backslashes
$username = stripslashes($_REQUEST[‘username’]);
//escapes special characters in a string
$username = mysqli_real_escape_string($con,$username);
$email = stripslashes($_REQUEST[‘email’]);
$email = mysqli_real_escape_string($con,$email);
$password = stripslashes($_REQUEST[‘password’]);
$password = mysqli_real_escape_string($con,$password);
$trn_date = date(“Y-m-d H:i:s”);

 // first check the database to make sure 

// a user does not already exist with the same username and/or email
$user_check_query = “SELECT * FROM ‘users’ WHERE username=’$username’ OR email=’$email’ LIMIT 1”;
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);

if ($user) { // if user exists
if ($user[‘username’] === $username) {
array_push($errors, “Username already exists”);

if ($user['email'] === $email) {
  array_push($errors, "email already exists");



    $query = "INSERT into `users` (username, password, email, trn_date)

VALUES (’$username’, ‘".md5($password)."’, ‘$email’, ‘$trn_date’)";
$result = mysqli_query($con,$query);
echo "

You are registered successfully.

Click here to Login
"; } }else{ ?>


<?php } ?> [/php]


You are inserting data regardless if the user exists, nothing is checking to see if it should stop.


duplicate of