运行我的查询,我收到错误..我的查询写在下面
$qry = "UPDATE Offer SET offer_year='$offeryear', " .
"course_code='$coursecode', offer_list='$offerlist', " .
"WHERE offer_id ='$offerid'";
我得到的错误是
ERROR: Record could not be added
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 'WHERE offer_id ='1'' at line 1
对我的更新查询进行了一些更改后仍然出现错误..
答案 0 :(得分:3)
如果您尝试逐个检查,则在comma
子句之前有额外的WHERE
$qry = "UPDATE Offer SET offer_year='$offeryear', " .
"course_code='$coursecode', offer_list='$offerlist' ". // remove comma here
"WHERE offer_id ='$offerid'";
作为旁注,如果变量的值( s )来自外部,则查询易受SQL Injection
攻击。请查看下面的文章,了解如何防止它。通过使用PreparedStatements
,您可以摆脱在值周围使用单引号。
答案 1 :(得分:2)
像这样更新您的更新查询
$qry = "UPDATE Offer
SET offer_year='$offeryear',
course_code='$coursecode',
offer_list='$offerlist'
WHERE offer_id ='$offerid'";
您在WHERE条件
之前添加了额外的逗号答案 2 :(得分:0)
试试这个(offerlist
之后有逗号):
$qry = "UPDATE Offer SET offer_year='$offeryear', " .
"course_code='$coursecode', offer_list='$offerlist' " .
"WHERE offer_id ='$offerid'";