简体   繁体   English

为什么此MySQL UPDATE命令不起作用?

[英]Why doesn't this MySQL UPDATE command work?

I've tried everything I know. 我已经尽力了。 I know it's not a database connection thing because I am running this in the same way I INSERT data and it's in the same function file. 我知道这不是数据库连接,因为我以与INSERT数据相同的方式运行此数据库,并且它位于同一功能文件中。

function update($name, email, $id) {
    $in = "UPDATE tablename 
           SET (name, email) VALUES('$name', '$email')  
           WHERE id = '$id'";

    mysql_query($in);
}

You SQL should be like this 你的SQL应该是这样的

$in = "UPDATE tablename
       SET name='$name', email='$email'
       WHERE id='$id'";

And as noted by @Falcon, you missed a $ in your function arguments. 就像@Falcon指出的那样,您在函数参数中错过了$

Your function 您的职能

function update($name, email, $id) {

says email and inside is using $email. 说电子邮件和内部使用$ email。 Change it to 更改为

function update($name, $email, $id) {

and check 并检查

try 尝试

update table_name
set
col1 = val1
col2 = val2
..........where id = $id;

The correct syntax is: 正确的语法是:

UPDATE tablename 
           SET name='$name',email='$email'
           WHERE id = '$id'

Note: Make sure you sanitize the input. 注意:请确保清理输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM