Im taking data from a HTML form and inserting into mysql database. Not all fields are mandatory and so Im trying to ignore those fields if they are empty.
Im have two problems. The first to find a way to deal with the blank fields and the second actually wrting to the database.
Here's what Ive done so far:
//check if fields are empty
$insertStrSet = '';
if($submitted_telephone !== '') {$insertStrSet .= 'telephone=\'$submitted_telephone\',';}
if($submitted_address !== '') {$insertStrSet .= 'address=\'$submitted_address\',';}
if($has_image !== ''){ $insertStrSet .= 'has_image=\'$has_image\',';}
if($final !== ''){ $insertStrSet .= 'image_id=\'$final\',';}
$insertStrSet = substr($insertStrSet,0,-1);
//create sql query
$insert = "INSERT INTO directory_listings cat_id='$submitted_category', user_id='$user_id', site_name='$submitted_name', description='$submitted_description', url='$submitted_url', country='$submitted_country', email='$submitted_email', $insertStrSet";
mysql_query($insert);