Bobby
asked on
Update / insert NULL instead of 0 or empty if no other data is entered
For the insert and update statements below, I need to check field canonical_url_id for an existing record value of 0 or empty... if it is, and if no other value has been entered, I need to replace the 0 or empty with NULL. How to, please?
$existing = $db->runQuery("SELECT COUNT(*) AS cnt FROM dynamic_url WHERE qm_url_id = ".$qm_url_id);
if($existing[0]['cnt'] == 0) {
$db->runQuery("INSERT INTO dynamic_url (qm_url_id, title, meta_keywords, meta_description, heading, canonical_url_id)
VALUES (".$qm_url_id.", '".addslashes($data['title'])."', '".addslashes($data['meta_keywords'])."',
'".addslashes($data['meta_description'])."', '".addslashes($data['heading'])."',
".intval($data['canonical_url_id']).")", true);
} else {
$db->runQuery("UPDATE dynamic_url SET title = '".addslashes($data['title'])."',
meta_keywords = '".addslashes($data['meta_keywords'])."',
meta_description = '".addslashes($data['meta_description'])."',
heading = '".addslashes($data['heading'])."',
canonical_url_id = ".intval($data['canonical_url_id'])."
WHERE qm_url_id = ".$qm_url_id, true);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.