简体   繁体   English

我的SQL UPDATE错误

[英]My SQL UPDATE error

I've been scratching my head for the last hour and just can't get this to work. 我在最后一小时一直在摸不着头脑,只是无法让它发挥作用。

Doing this query: 执行此查询:

$dbtoken = mysql_real_escape_string($invite_token);
$dbexpire = mysql_real_escape_string($invite_expire);
$dbid = mysql_real_escape_string($uid);
$update_user = mysql_query("UPDATE inviters SET invitetoken='$dbtoken', inviteexpire='$dbexpire' WHERE uid='$dbid'");
$save = mysql_query($update_user) or die(mysql_error());

It gives me this error: 它给了我这个错误:

You have an error in your SQL syntax; 您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 检查与MySQL服务器版本对应的手册,以便在第1行的“1”附近使用正确的语法

You are sending the result of your first query as an sql statement for your second query: 您将第一个查询的结果作为第二个查询的sql语句发送:

$update_user = mysql_query("UPDATE inviters SET invitetoken='$dbtoken',
inviteexpire='$dbexpire' WHERE uid='$dbid'");
$save = mysql_query($update_user) or die(mysql_error());

$update_user contains the result, and you feed it back to mysql_query. $ update_user包含结果,然后将其反馈给mysql_query。 Try this instead: 试试这个:

$update_user = "UPDATE inviters SET invitetoken='$dbtoken',
inviteexpire='$dbexpire' WHERE uid='$dbid'";
$save = mysql_query($update_user) or die(mysql_error());

BTW: Use Mysqli instead of Mysql_ statements, they're deprecated and unsafe. 顺便说一句:使用Mysqli而不是Mysql_语句,它们已被弃用且不安全。

There is a error You are trying to execute your query twice. 出现错误您尝试执行两次查询。 Remove second execution of it.ie remove this 删除它的第二次执行。删除它

 $save = mysql_query($update_user) or die(mysql_error());

it is trying to do this 它试图这样做

$save = mysql_query(1);

which is wrong 这是错的

You are doing mysql_query(); 你正在做mysql_query(); twice. 两次。 Once in the last line. 一旦进入最后一行。 And once in the line above it. 而且一旦在它之上。

The first time it returns 1 (success) 第一次返回1 (成功)

The second time you try to execute 1 as a query 第二次尝试执行1作为查询

Ps. PS。 Scratching your head for an hour can cause skin irritation. 抓头一小时会引起皮肤刺激。

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

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