2014-11-20 70 views
-1

我有以下一段代碼。讓我發狂。找不到我的錯誤。看起來像在我的sql語法中使用限制有衝突,並且變量$ result中的mysql_query不返回任何內容。sql語法返回mysql_num_rows()期望參數1是資源,布爾給定

<?php 

$sql = " select * from `share` where (`category` LIKE '$category' and `country` LIKE '$country' and `city` LIKE '%$city_name%' and `job_title` LIKE '%$job_name%' and `user_id`!='$session_user_id') 
     order by `share_id` desc LIMIT 3; "; 

$result = mysql_query($sql); 

if(mysql_num_rows($result) ==0){ 
    echo"success"; 
} 

?> 
+0

'$ result = mysql_query($ sql)or die(mysql_error());'看看是否會產生任何錯誤。 – 2014-11-20 18:39:54

+0

鑑於SQL注入漏洞,查詢導致錯誤並不奇怪。從字面上看,任何SQL代碼都可能試圖執行。 – David 2014-11-20 18:43:43

+0

我將它更改爲$ result = mysql_query($ sql)或死(mysql_error());給我未申報的變量:3LIMIT – user2491321 2014-11-20 18:45:48

回答

0

引起問題的字符串連接問題。

$sql = "select * from `share` 
     where 
      (`category` LIKE '". $category ."' 
      and `country` LIKE '". $country ."' 
      and `city` LIKE '%". $city_name ."%' 
      and `job_title` LIKE '%". $job_name ."%' 
      and `user_id` != '". $session_user_id ."') 
     order by `share_id` desc 
     limit 3"; 
+0

仍然沒有...如果我刪除限制3有效。問題是我可以看到的極限3 – user2491321 2014-11-20 18:43:08

相關問題