0

I have created a registration page in PHP and MySQL.

How to prevent user from registering again with the following details: "fname,lname,user_name,email,bikeno,mobileno".

I tried with the following select statement, but its not working.

$sql="select * from user_registration where fname='".$fname."' and lname='".$lname."' and user_name='".$user_name."' and  email='".$email."' and bikeno='".$bikeno."' and mobileno='".$mobileno."'";

The Values are going to database with same details also

What I need is if the user gives any duplicate details in these columns the user is not registered.

9
  • 1
    If you want to avoid duplicates on individual columns use OR instead of AND Commented Nov 30, 2016 at 12:39
  • 1
    you should not allow user with same bike number or same mobile number or user name,, Users may have same first name or last name Commented Nov 30, 2016 at 12:39
  • 1
    Before inserting use select statement if result is 1 then prompt user already created else use insert statement. Commented Nov 30, 2016 at 12:40
  • 1
    That should work for you, is it? Commented Nov 30, 2016 at 12:47
  • 1
    On an additional note, you should not store passwords as plain text Commented Nov 30, 2016 at 12:49

2 Answers 2

1
$sql="select * from user_registration where fname='".$fname."' or lname='".$lname."' or user_name='".$user_name."' or  email='".$email."' or bikeno='".$bikeno."' or mobileno='".$mobileno."'";

//After select query check if users exist or not as

$result = $con->query($sql);

if($result->num_rows > 0)
{
    //Here Prevent the user registration with the same details
}
else
{
    //Here Insert record into the table
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try this code

$res = mysqli_query($con,"$sql="select * from user_registration where fname='".$fname."' and lname='".$lname."' and user_name='".$user_name."' and  email='".$email."' and bikeno='".$bikeno."' and mobileno='".$mobileno."'";
");

if(mysqli_num_rows($res) > 1)
echo "User Already Exist";
else
// run insert query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.