谁能看出为什么这不起作用?
$category = 1;
$CategoryResult = mysql_query("SELECT * FROM Category WHERE Index = '$category'");
if (!$CategoryResult)
die("Could not retrieve results from category $category: " . mysql_error());
Mysql报错如下:
Could not retrieve results from category 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Index = '1'' at line 1
Index是表Category的自增主键。
最佳答案
也许索引是一个保留字。试试这个
$CategoryResult = mysql_query("SELECT * FROM Category c WHERE c.`Index` = '$category'");
并检查索引是字符串还是整数
关于php mysql WHERE子句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5081520/