I am trying to use update to update data in the table, but if I don't have data in the field, I get an error. I have lots of optional fields, and would like an easy work around for this. Here is the code I have now, but I need to add this for roughly 20 forms and 20-50 fields each form.
Any suggestions would be great! Thanks
// first add required fields...
$query = "UPDATE fcustomer SET TIN='$ssn', TIN1='$SSN1', TIN2='$SSN2', TIN3='$SSN3', FirstName='$FirstName',
LastName='$LastName', Address='$Address', City='$City', State='$State', Zip1='$Zip1',
Zip='$zip', Email='$Email'
WHERE UserName = '$UserName' && Password = '$Password'";
$result = mysql_query($query);
if (!$result) {echo "die"; die('Could not insert data in customer file.'.$mysql_error());}
// add fields that may or may not exist
$query = "UPDATE fcustomer SET Zip='$zip'"; // something has to go in
if ($Zip2 !="") $query.=", Zip2='$Zip2'";
if ($Phone1 !="") $query.=", Phone1='$Phone1'";
if ($Phone2 !="") $query.=", Phone2='$Phone2'";
if ($Phone3 !="") $query.=", Phone3='$Phone3'";
if ($phone !="") $query.=", Phone='$phone'";
$query.=" WHERE UserName = '$UserName' && Password = '$Password'";
$result = mysql_query($query);
if (!$result) {echo "die"; die('Could not update data in customer file.'.$mysql_error());}