使用更新查询复制列数据
我需要将名为 TEAM 的列中的值从一行复制到另一行。两行需要具有相同的团队名称。这是我的查询不起作用:
$query = "UPDATE profiles SET team = (SELECT team FROM profiles WHERE id = '$coach_id') WHERE id = '$player_id'";
我尝试删除单引号,删除“FROM profile”,将值更改为 table.value,尝试提供 newdata.clan 别名,我什至尝试将值更改为整数参数。什么都不起作用,这就是我得到的:
错误:您的 SQL 中有错误 句法;检查手册 对应你的MySQL服务器 正确使用语法的版本 靠近 'WHERE id = '') WHERE id = ''' at 第 3 行
I need to copy the value in a column named TEAM from one row into another row. Both rows need to have the same team name. This is my query that doesn't work:
$query = "UPDATE profiles SET team = (SELECT team FROM profiles WHERE id = '$coach_id') WHERE id = '$player_id'";
I have tried removing single quotes, removing "FROM profiles", changing value to table.value, tried to give a newdata.clan alias, and I have even tried changing the values to integers instead of parameters. Nothing works, and this is what I get:
Error: 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 id = '') WHERE id = ''' at
line 3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另外,您应该将 PHP 变量括在大括号中:
Also, you should surround your PHP variables in curly braces:
来自 MySQL 手册:
来源:http://dev.mysql.com/doc/ refman/5.0/en/update.html
使用FinalForm写的方法:
From the MySQL manual:
Source: http://dev.mysql.com/doc/refman/5.0/en/update.html
Use the method that FinalForm wrote: