MyBB Community Forums

Full Version: MySQL query value + 1
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey,

i'm making right now little script and have little problem with mysql query
Code what i use:
$db->update_query('mybb_custom', array("ActTimes" => "ActTimes+1", "Server" => $ServerChoosed), 'ID = "'.$Rights.'"');

"ActTimes+1" - How to get that working?
Sorry for bad explanation Smile
I am not sure but this should work.

$db->update_query('mybb_custom', array("ActTimes" => ActTimes + 1, "Server" => $ServerChoosed), 'ID = "'.$Rights.'"'); 
Hi,

I don't believe that update_query can do what you're trying to do. You'll have to use write_query with a full query:

$ServerChoosed = $db->escape_string($ServerChoosed);
$Rights = $db->escape_string($Rights);
$db->write_query("UPDATE mybb_custom SET ActTimes = ActTimes + 1, Server = '{$ServerChoosed}' WHERE ID = '{$Rights}'");
The inTech solution worked, thanks to both of you.

//Edit::
Sorry, inTech solution marked it as 1.
And the Euan T solution working, thanks both of you for help.
(2016-04-27, 12:36 PM)Euan T Wrote: [ -> ]I don't believe that update_query can do what you're trying to do. You'll have to use write_query with a full query:
$db->update_query('mybb_custom', array('ActTimes' => 'ActTimes+1'), 'ID = "'.$Rights.'"', '', true);
Notice the fifth parameter. Wink
(2016-04-27, 12:54 PM)StefanT Wrote: [ -> ]
(2016-04-27, 12:36 PM)Euan T Wrote: [ -> ]I don't believe that update_query can do what you're trying to do. You'll have to use write_query with a full query:
$db->update_query('mybb_custom', array('ActTimes' => 'ActTimes+1'), 'ID = "'.$Rights.'"', '', true);
Notice the fifth parameter. Wink

Interesting, I'd forgotten that was there!