我希望查詢最初返回c_id> 0的所有記錄,然後根據通過文本框提供的後續條件進行過濾。但是,在第一次訪問頁面時,我沒有收到任何記錄。下面是代碼:SQL查詢失敗
$ctitle = mysql_real_escape_string($_POST['ctitle']);
$csubject = mysql_real_escape_string($_POST['csubject']);
$creference = mysql_real_escape_string($_POST['creference']);
$cobjecttype = mysql_real_escape_string($_POST['cobjecttype']);
$cmaterial = mysql_real_escape_string($_POST['cmaterial']);
$ctechnic = mysql_real_escape_string($_POST['ctechnic']);
$cartist = mysql_real_escape_string($_POST['cartist']);
$csource = mysql_real_escape_string($_POST['csource']);
$sql = "SELECT * FROM collections WHERE (
c_id>0 AND
`ctitle` LIKE '{$ctitle}' AND
`csubject` LIKE '{$csubject}' AND
`creference` LIKE '{$creference}' AND
`cobjecttype` LIKE '{$cobjecttype}' AND
`cmaterial` LIKE '{$cmaterial}' AND
`ctechnic` LIKE '{$ctechnic}' AND
`csource` LIKE '{$csource}' AND
`cartist` LIKE '{$cartist}'
)ORDER BY c_id DESC";
當我附和查詢我得到如下印刷代替:
request "Could not execute SQL query" SELECT * FROM collections WHERE (c_id>0 AND `ctitle` LIKE '' AND `csubject` LIKE '' AND `creference` LIKE '' AND `cobjecttype` LIKE '' AND `cmaterial` LIKE '' AND `ctechnic` LIKE '' AND `csource` LIKE '' AND `cartist` LIKE '')ORDER BY c_id DESC
哪裏應該何去何從?
嗨,我按照你的建議,但仍然是相同的錯誤。我也刪除了一些條件,只保留:$ sql =「SELECT * FROM collections WHERE c_id> 0 ORDER BY c_id DESC」;並返回所有記錄。但我需要這些標準才能工作。 – 2013-04-10 07:16:53
空間也是我能發現的唯一錯誤......你究竟得到了什麼錯誤? – UrGuardian4ngel 2013-07-17 23:53:49