2011-05-30 24 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不明確。

相關問題