This query is intended to update the inUse variable if the result of a form input, e.g. $_POST[‘eventID’] matches the eventID in the database, thus changing the inUse value for that event to 1, and all others to zero.
mysql_query("UPDATE events SET inUse=IF('$_POST['eventID']' = eventID, 1, 0)");
The database requires an integer, however I am concerned as I’ve dumped the value for $_POST[‘eventID’] which is showing up as a string. I’ve tried using intval and int to no avail.
Or is the a problem in my query syntax?
Thanks 🙂
Try this:
This assumes that
inUseis a boolean (which in mysql is implemented as aTINYINTwith values either1or0, but whatever the case, mysql converts between boolean/int values just fine)