xv47
xv47

Reputation: 992

Update multiple rows/columns in php/mysql

I have the following line:

$reset = "UPDATE pidgeon SET obt='" . $hour . "' WHERE tag='" . $tag . "'";

Which updates just fine. However I need to update an additional row (kill) and I keep getting syntax errors. I've tried the following:

$reset = "UPDATE pidgeon SET obt='" . $hour . "', kill='1' WHERE tag='" . $tag . "'";

$reset = "UPDATE pidgeon SET kill='1', obt='" . $hour . "' WHERE tag='" . $tag . "'";

$reset = "UPDATE pidgeon SET obt='" . $hour . "', kill='" . $num . "' WHERE tag='" . $tag . "'";

I've even done 2 separate UPDATE queries and I get the same syntax error message. I've narrowed it down to the system having issue with the kill row but I'm not sure what's the issue. I've tried setting kill as INT, SMALLINT, BOOL, even CHAR and trying to use 't/f' as values for it. I still get a syntax error. Any suggestions?

Upvotes: 1

Views: 130

Answers (2)

Kirk
Kirk

Reputation: 5077

Kill is actually a syntax, you can't use them directly.

Just replace kill with another name.

Upvotes: 0

Amal Murali
Amal Murali

Reputation: 76666

KILL is a reserved keyword, so you'll have to enclose it in backticks, like so:

$reset = sprintf("UPDATE pidgeon SET `kill`='1', obt='%s' 
WHERE tag='%s'", $hour, $tag);

Upvotes: 1

Related Questions