I want to build query using two array 1 for column and another for value. I have 3 integer columns in first array for which I don't want to store 0 as default so i want to set NULL, I want to check if any value entered for it, if not entered i want to set NULL for it . But when i create query i cant see NULL, i just see null replaced by blank. Seems like PHP is stripping out the NULL word ?
$set_null = array("asst_phone","mailing_zip","other_zip");
foreach($columns as $key=>$col){
if(in_array($col,$set_null) && $values[$key] == ""){
$val[$key] = NULL;
}
else
$val[$key] = "'".$values[$key]."'";
}
$query_vals = "";
foreach($val as $qval){
if($qval == "") $query_vals .= NULL;
$query_vals .= $qval;
}
echo $query_vals;
It generates query like below
INSERT INTO zoho_contacts (`contactid`,`smownerid`,`contact_owner`,`lead_source`,`first_name`,`last_name`,`accountid`,`account_name`,`email`,`title`,`department`,`phone`,`home_phone`,`other_phone`,`fax`,`mobile`,`date_of_birth`,`assistant`,`asst_phone`,`reports_to`,`smcreatorid`,`created_by`,`modifiedby`,`modified_by`,`created_time`,`modified_time`,`mailing_street`,`other_street`,`mailing_city`,`other_city`,`mailing_state`,`other_state`,`mailing_zip`,`other_zip`,`mailing_country`,`other_country`,`description`,`email_opt_out`,`skype_id`,`salutation`,`add_to_quickbooks`,`secondary_email`) values ('418176000000052001','418176000000047003','','','','','418176000000047027','','','','','02164 25452132','','','','9798659821','','',,'','418176000000047003','','418176000000047003','','','','','','','','','',,,'','','','','','Mr.','','')
My mysql column structure
column properties = NULL => Yes, DEFAULT => NULL, right ??