简体   繁体   English

MySQLi UPDATE where子句不起作用

[英]MySQLi UPDATE where clause not working

I wrote code that is suposed to update the "user level" stored in the column "level" in the table "users", for the user specified by the variable "$x5_input_username". 我编写了用于为变量“ $ x5_input_username”指定的用户更新存储在表“ users”的“ level”列中的“ user level”的代码。

$x_changelvl_sql = "UPDATE users SET level='$x5_input_newlevel' WHERE `username`=$x5_input_username";

When I do this using the userlevel "2" and username "TestUser" (which both exist in the database), it gives me this error: 当我使用用户级别“ 2”和用户名“ TestUser”(都存在于数据库中)执行此操作时,它给了我这个错误:

Error updating record: Unknown column 'TestUser' in 'where clause' 更新记录时出错:“ where子句”中的未知列“ TestUser”

Quote your string in the where clause where clause引用您的字符串

$x_changelvl_sql = "UPDATE users 
    SET level='$x5_input_newlevel' 
    WHERE `username`='$x5_input_username'";

Better yet, start using MySQLi with prepared statements and bind variables 更好的是,开始将MySQLi与已准备好的语句和绑定变量一起使用

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

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