php - 列名称为 '%' 的 Mysql 查询未在 PHP 中执行

标签 php mysql web

我有一个Mysql查询如下

$query = "UPDATE student_database SET fname='$fname',mname='$mname',lname='$lname',dob='$dob',Age='$age',Sex='$sex',Caste='$caste',dept='$dept', SSC%=$ssc , HSC%=$hsc, ATKTs=$atkt, Last_sem%=$lastsem, Aggregate%=$agg WHERE student_id=$id  ; ";

某些列名称中包含“%”符号。 Mysql执行时抛出以下错误

Cannot execute.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 '%=79.6 , HSC%=81.83, ATKTs=5, Last_sem%=52.35, Aggregate%=53.6 WHERE student_id=' at line 1

无法弄清楚问题我尝试过“\”、“#”、“%%”作为转义字符但无法弄清楚。

最佳答案

用反引号括起来,告诉 SQL 它是一个列,这有效吗?

$query = "UPDATE student_database SET fname='$fname',mname='$mname',lname='$lname',dob='$dob',Age='$age',Sex='$sex',Caste='$caste',dept='$dept', `SSC%`=$ssc , `HSC%`=$hsc, ATKTs=$atkt, `Last_sem%`=$lastsem, `Aggregate%`=$agg WHERE student_id=$id  ; ";

关于php - 列名称为 '%' 的 Mysql 查询未在 PHP 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9316076/

相关文章:

php - 在php中的url中传递变量

java - 错误 1136 (21S01) : Column count doesn't match value count at row 1

php - 搜索结果的多样性

mySQL - 抓取数据同时确保字段是唯一的

Tomcat 在不同的机器上表现不同

php - 如何优化导入/导出数据的查询,从 2 个表到 1 个表,记录超过 200k

php - 为什么 rand() 不是真正随机的?

rest - Redis/Memcached ReST 外部服务缓存

javascript - 如何制作气泡轮播?

PHP 不将变量传递给其他页面