PHP mysql_query - 使用所有变量更新

标签 php mysql

Possible Duplicate:
Can a number used to name a sql column

我试图找出这段代码有什么问题

$query = "UPDATE $table SET '$_GET[qty]'=$_GET[newprice] WHERE 'id'='1'";

this is what $query looks like - UPDATE retail_12x18 SET '25'=100 WHERE 'id'='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 ''25'=100 WHERE 'id'='1'' at line 1

我已经在各个方向都加上了反引号,但无法让它通过,总是出现相同的错误消息。

enter image description here

最佳答案

在字段名称周围使用反引号:

UPDATE table SET `25` = '{thevalue}', `100` = '{thevalue}', `200` = '{thevalue}' WHERE wherefield = '{wherevalue}'

参见此处(查找反引号单词):http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

关于PHP mysql_query - 使用所有变量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7973780/

相关文章:

PHP 将带撇号的字符串传递给 shell_exec

mysql - 重复键更新时的 SQL 更新

php - 使用 PHP CSV 导入脚本时出现 ENCLOSED BY 错误

php - 意外的基数违规(子查询返回超过 1 行)

php - MySQL RegEx 搜索每一列

php - PHP/MySQL查询String中有句点(.)的方法

php - 根据月份对数据库结果对象(数组)进行排序

javascript - 为什么我的代码可以在本地主机上的 Internet Explorer 版本 8 上运行,而不是在服务器上运行,但不能在 Internet Explorer 版本 10 上运行

php - 如何为 Laravel 安装所有必需的 PHP 扩展?

javascript - Ajax/Jquery - 获取提交表单响应的记录