0

I am very new in php and mysql programming. I have recently found the tutorial on YouTube to create a login and registration page. I am making some changes in the code to add some more features which are not given in tutorials. But when i execute the code, i am always getting this error "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\reg_log\register.php on line 25

I am actually adding the EMAIL feature, so the user add their email to the database.

Here is my php code:

<?php
if(isset($_POST["submit"])) {
    $user=$_POST['user'];
    $pass=$_POST['pass'];
    $email=$_POST['email'];


$query=mysql_query("SELECT * FROM users WHERE username='$user' email='$email'");
$numrows=mysql_num_rows($query);
if($numrows==0)
{
$sql="INSERT INTO users(username,password,email) VALUES ('$user','$pass','$email')";

$result=mysql_query($sql);

if($result) {
    echo "User Account Successfully Created";
} else {
    echo "Unable To Create User Account";
}

} else {
echo "That username already exists! Please choose another username";
}
}
?>
  • Your query failed and you need to find out why. You really should add error checking and handling to your code. Start with mysql_error() to see what the SQL error is. – John Conde Mar 26 '14 at 17:50

1 Answers1

2

You forgot the AND keyword between your query.

$query=mysql_query("SELECT * FROM users WHERE username='$user' AND email='$email'");
                                                               ^^^
Shankar Narayana Damodaran
  • 66,874
  • 43
  • 94
  • 124