$querynotis = "SELECT * FROM notifications WHERE pid = " . $_SESSION['sess_id'] . " AND read = 0";
它给了我错误;
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 'read = 0' at line 1
如果我删除:
AND read = 0
部分,它工作得很好。我可能做错了什么?
最佳答案
READ 是保留关键字,恰好是您的列的名称。为了避免语法错误,应使用反引号对列名进行转义。例如,
$pid = $_SESSION['sess_id'];
$querynotis = "SELECT * FROM notifications WHERE pid = $pid AND `read` = 0";