I have a script that collects data from an HTML form and inserts it into a MySQL database. Not all fields are required. I want empty fields to be inserted as NULL instead of zero length strings.
mysql_query (
"INSERT INTO contacts SET
first_name = '$first_name',
last_name = '$last_name',
email = '$email',
address1 = '$address1',
address2 = '$address2',
city = '$city',
state = '$state',
zip = '$zip',
phone_area = '$phone_area',
phone_3 = '$phone_3',
phone_4 = '$phone_4'
");
The "address2" field is not required and is often left blank. How do I insert it as NULL instead of just empty?