aenugula karthik aenugula karthik - 3 days ago 4
PHP Question

Select Statement in PHP Script

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.

Answer

$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."'";

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
 }
Comments