我试图显示发布订单的记录,并让用户搜索customer_name和release_date。
我收到此错误:
错误:"您的SQL语法出错;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'发布喜欢' %%' '在第19行" // HTML表单 //用于搜索的PHP代码 $搜索= $ _ POST ['搜索']; $搜索1 = $ _ POST ['搜索1'];
$result=mysql_query("SELECT order1.order_id,
order1.customer_id,
order1.release as releasedate,
customer1.customer_name as Customer
FROM order1 left join customer1 on order1.customer_id=
customer1.customer_id
where customer_name LIKE '%$search%'
And release Like '%$search1%'
order by release Asc") or die(mysql_error());
答案 0 :(得分:1)
release是mysql保留字,可以看作here。
尝试逃避你的查询:
SELECT
`order1`.`order_id`,
`order1`.`customer_id`,
`order`.`release` AS `releasedate`,
`customer1`.`customer_name` AS `Customer`
FROM
`order1`
LEFT JOIN `customer1` ON `order1`.`customer_id` = `customer1`.`customer_id`
WHERE
`customer_name` LIKE '%$search%'
AND `release` LIKE '%$search1%'
ORDER BY
`release` ASC
为了安全起见,我总是逃避所有的表名和列名。并且使用一种写作风格也是一个好主意 - 在一个你喜欢的代码中,在另一个你喜欢的代码中 - 它将帮助你修改你的代码。