2011-05-30 89 views
0

可能重复:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in selectmysql_num_rows()预计参数1是登记表格上资源错误消息

我正在与两个MySQL表对应一个登记表上我的数据库。

  1. 用户登陆 - 包含所有与该网站
  2. userlogin_fb注册的详细信息 - 包含使用FB连接设备

现在,用户的所有细节,当用户注册后不能有一个冲突用户名或邮箱地址。我现在推行的验证码在两个表检查的电子邮件地址(这将被用来作为用户名的验证参考):

,但我不断收到以下错误信息:

警告:mysql_num_rows()预计 参数1是资源,布尔 在register.php给出线144

我怎么去有关解决呢?

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

任何帮助将不胜感激 - 谢谢!

回答

1

检查您的查询是否正确,然后计算行数。

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

在你的情况下,脚本将die()。检查是什么导致它死亡并修复它。一般来说,您必须始终检查您的查询是否返回truefalse,然后在其上工作

0

处理查询时发生错误。

使用mysql_errno([$con])mysql_error([$con])来获取错误。

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

只使用模具进行调试,登录生产。否则,你可以使SQL注入更容易。 (好吧,可能仍然是voulnerable,但它是盲注SQL然后,这是很难脱下来)

2

您的查询无效,导致它失败。您正在从两个不同的行列中选择一个“电子邮件”字段,但不要在WHERE子句中提供表,因此where email = xxx不明确。