Checkbox unchecked not returning a 0 in DB
I have a couple of checkboxes on a page that work and pass a value of 1 when checked, but when unchecked, I am getting a value of NULL rather than 0. I am using the 0 for other functions across my pages, so need it to work!
I used security assist to build a log in and registration / user update / password reminder etc, but none of the menus or check boxes could have BD values tied to them during in the wizard, so I then manually tied the menus and checkboxes to the DB. The menus work fine, but the checkboxes only work when a value of 1 (checked) is passed to the DB.
I manually tied it by selecting the checkbox and in the properties panel giving a value of 1 and then clicking the Dynamic button setting the check if to <?php $row_SecurityAssisttblstudents['fld_sALLERGIES'] ?> and the value to 1.
Here's the checkbox code:
<input <?php if (!(strcmp($row_SecurityAssisttblstudents['fld_sALLERGIES'],1))) {echo "checked=\"checked\"";} ?> type="checkbox" name="User_Update_group_11_Any_allergies" id="User_Update_group_11_Any_allergies" value="1" class="formCheckboxField_Standard"<?php echo $row_SecurityAssisttblstudents["fld_sALLERGIES"]; ?> tabindex="11">
And the update code:
<?php
// WA DataAssist Update
if ((isset($_POST["UserUpdate_submit"]) && $_POST["UserUpdate_submit"] != "")) // Trigger
{
$WA_connection = $conn_mrs;
$WA_table = "tbl_students";
$WA_redirectURL = "index.php?success=1";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = true;
$WA_indexField = "fld_sID";
$WA_fieldNamesStr = "fld_sNAME|fld_sPASSWORD|fld_sGENDER|fld_sHOUSENO|fld_sSTREET|fld_sDISTRICT|fld_sTOWN|fld_sCOUNTY|fld_sPOSTCODE|fld_sACTIVITY|fld_sALLERGIES|fld_sMEDICAL";
$WA_fieldValuesStr = "".((isset($_POST["User_Update_group_Full_name"]))?$_POST["User_Update_group_Full_name"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_Password"]))?$_POST["User_Update_group_Password"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_Gender"]))?$_POST["User_Update_group_Gender"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_House_No"]))?$_POST["User_Update_group_House_No"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_Street"]))?$_POST["User_Update_group_Street"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_District"]))?$_POST["User_Update_group_District"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_Town"]))?$_POST["User_Update_group_Town"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_County"]))?$_POST["User_Update_group_County"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_Postcode"]))?$_POST["User_Update_group_Postcode"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_10_Activity"]))?$_POST["User_Update_group_10_Activity"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_11_Any_allergies"]))?$_POST["User_Update_group_11_Any_allergies"]:"") ."" . $WA_AB_Split . "".((isset($_POST["User_Update_group_1_Medical_requirements"]))?$_POST["User_Update_group_1_Medical_requirements"]:"") ."";
$WA_columnTypesStr = "',none,''|',none,''|none,none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|none,none,NULL|none,none,NULL|none,none,NULL";
$WA_comparisonStr = "=|=|=|=|=|=|=|=|=|=|=|=";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode($WA_AB_Split, $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_where_fieldValuesStr = "".((isset($_SESSION["SecurityAssist_fld_sID"]))?$_SESSION["SecurityAssist_fld_sID"]:"") ."";
$WA_where_columnTypesStr = "none,none,NULL";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode($WA_AB_Split, $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);
$WA_connectionDB = $database_conn_mrs;
mysql_select_db($WA_connectionDB, $WA_connection);
@session_start();
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
What am I missing?
Thanks