php - Prevent MySQL from updating column with empty string? -
found reply helpful, have 100 inputs need updating.
i have code cleaning values:
foreach($_post $key => $value) { $data[$key] = filter($value);}
can add together reply above link code impact 100 inputs or forced add together if clause on each input.
thank you.
$update_arr = array(); foreach ($_post $key => $value) { if (strlen($value) !== 0) { $update_arr[] = $key.' = "'.filter($value).'"'; } } $update_string = implode(',',$update_arr); $table = ''; $where = ''; $format = "update %s set %s %s"; $sql = sprintf($format,$table,$update_string,$where);
php mysql validation
No comments:
Post a Comment