MySQLi Update form checkbox updating database with a value despite not being checked?
I've got an update form that uses a checkbox to update a TINYINT field in a database table with either a Yes / 1 or No / 0 value.
However, even when the checkbox is left unchecked it still updates the TINYINT field with a 1?
This is the checkbox code:
<input name="SMTeventdel" type="checkbox" id="SMTeventdel" value="1" <?php if (!(strcmp(($rsEDITEVENT->getColumnVal("SMTeventdel")),1))) {echo "checked=\"checked\"";} ?>>
And this is the update code:
<?php
if (isset($_POST["formEDITEVENTBTN"]) || isset($_POST["formEDITEVENTBTN_x"])) {
$UpdateQuery = new WA_MySQLi_Query($SMTmysqli);
$UpdateQuery->Action = "update";
$UpdateQuery->Table = "SMTevents";
$UpdateQuery->bindColumn("SMTeventtitle", "s", "".((isset($_POST["SMTeventtitle"]))?$_POST["SMTeventtitle"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventdesc", "s", "".((isset($_POST["SMTeventdesc"]))?$_POST["SMTeventdesc"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventdate", "t", "".((isset($_POST["EDITEVENTPICKER"]))?$_POST["EDITEVENTPICKER"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventtime", "s", "".((isset($_POST["SMTeventtime"]))?$_POST["SMTeventtime"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTvenueID", "i", "".((isset($_POST["SMTeventvenue"]))?$_POST["SMTeventvenue"]:"") ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventimg", "s", "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"] ."", "WA_DEFAULT");
$UpdateQuery->bindColumn("SMTeventdel", "i", "".((isset($_POST["SMTeventdel"]))?$_POST["SMTeventdel"]:"") ."", "WA_DEFAULT");
$UpdateQuery->addFilter("SMTeventID", "=", "i", "".($rsEDITEVENT->getColumnVal("SMTeventID")) ."");
$UpdateQuery->execute();
$UpdateGoTo = "events.php";
if (function_exists("rel2abs")) $UpdateGoTo = $UpdateGoTo?rel2abs($UpdateGoTo,dirname(__FILE__)):"";
$UpdateQuery->redirect($UpdateGoTo);
}
?>
Page attached also. Thank you.
NJ