0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I am working on a registration form which corresponds with two mysql tables in my database.

  1. userlogin - contains all the details registered with the site
  2. userlogin_fb - contains all the details of users using the fb connect facility

Now when a user signs up there cannot be a clash of username or email address. I am now implementing the validation code for checking the email addresses across the two tables (which will be used as a reference for the username validation):

But i keep receiving the following error message:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in register.php on line 144

How do i go about resolving this?

//select all rows from our users table where the emails match
$res1 = mysql_query("SELECT * FROM `userloginl.email`,`userlogin_fb.email` WHERE `email` = '".$email."'");
$num1 = mysql_num_rows($res1);

//if the number of matchs is 1
if($num1 == 1){
    //the email address supplied is taken so display error message
    echo "<center>The <b>e-mail</b> address you supplied is already taken</center>";
    include_once ("resources/php/footer.php");      
    exit;   
}else{
    //finally, otherwise register there account }

Any help would be appreciated - thanks!

Community
  • 1
  • 1
methuselah
  • 12,766
  • 47
  • 165
  • 315

3 Answers3

2

Your query is invalid, causing it to fail. You're selecting an 'email' field from two different ables, but don't give a table in the WHERE clause, so where email = xxx is ambiguous.

Marc B
  • 356,200
  • 43
  • 426
  • 500
1

check if your query is correct or not and then count the rows.

//select all rows from our users table where the emails match
$res1 = mysql_query("SELECT * FROM `userloginl.email`,`userlogin_fb.email` WHERE `email` = '".$email."'");

// checks if results where return without any errors
if(!$res1){
    die('There was an error in query '. mysql_error());
}

$num1 = mysql_num_rows($res1);

//if the number of matchs is 1
if($num1 == 1){
    //the email address supplied is taken so display error message
    echo "<center>The <b>e-mail</b> address you supplied is already taken</center>";
    include_once ("resources/php/footer.php");      
    exit;   
}else{
    //finally, otherwise register there account
}

in your case the script will die(). check what was causing it to die and fix it. in general you must always check if your queries returned true or false and then work on them

afarazit
  • 4,907
  • 2
  • 27
  • 51
0

There was an error while processing the query.

Use mysql_errno([$con]) and mysql_error([$con]) to get the error.

if (!$res1) {
    die('Invalid query: ' . mysql_error());
}

use die only for debugging, logging in production. Otherwise you can make it voulnerable to SQL Injection. (Well might still be voulnerable, but it's Blind SQL Injection then, which is much harder to pull off)

Máthé Endre-Botond
  • 4,826
  • 2
  • 29
  • 48