开发者

Syntax on this MySQL query might be wrong

Is there something wrong with the syntax on this MySQL query?

Thanks in advance,

John

$ttquery = sprintf("Update login SET ".$row['ttemail']." = '1' WHERE username = ".$row['username'].""); 

EDIT: Okay, per Pekka's request, I echoed out the actual query value, and that gave me some ideas. Now I'm using this:

$ttquery = "Update login SET ttemail = 1 WHERE username = ".$row['username']."";

and I get this error: Unknown column 'admin' in 'where clause'. "admin" is the first username that meets the condition I want to run t开发者_高级运维his query for... it's not the name of a field. Any ideas on why I'm getting the error?

EDIT: Here is the MySQL echoed MySQL query if that helps:

Update login SET ttemail = 1 WHERE username = admin


You probably need single quotes around username

$ttquery = "Update login SET ".$row['ttemail']." = '1' WHERE username = '".$row['username']."'";

If you're using sprintf, you would have:

$ttquery = sprintf("Update login SET %1$s = '1' WHERE username = '%2$s'", $row['ttemail'],$row['username']);


Update login SET ttemail = 1 WHERE username = admin

In SQL, strings are surrounded by single quotes and table/column names are unquoted. You need to fix your PHP code so you generate this:

Update login SET ttemail = 1 WHERE username = 'admin'

Try to make sure you understand basic SQL before banging your head against PHP ;-)


try this

$ttquery = sprintf("Update login SET ".$row['ttemail']." = '1' WHERE username = '" . $row['username'] ."'"

i.e., username='[your value]'


This should work:

$ttquery = "Update login SET ".$row['ttemail']." = '1' WHERE username = '".$row['username']."'";


man, be careful about sql injections. Also, why call sprintf() if you dont actually use it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜