I have a form that has several fields that are optional. When the mysql query saves the data from the form it fails if any of the fields are are left blank.
What is the best way of getting around this? I would prefer the field in the database to remain empty rather than having to enter data just to keep the query happy.
$sql = "INSERT INTO s_num_serialz (id, name, date_entered, created_by, account_name, type, supply_type, covered_by_support, install_date, job_number, replacement_for) VALUES ('$id', '$serial_num', NOW(), '$diary_id', '$account', '$type', '$supply_type', $support_cover, '$dispatch_date', '$job_num', '$old_serial_num')";
$result = $mysqli->query($sql) or die($mysqli->error.__LINE__);
It’s a straight forward insert but if one of the values, say $job_number, is empty the query will fail
Well check if a field is empty after recieving
If you are using the query of form
try switching to
And add some code to help us answer because it should work.