Jump to content

UPDATE query with blank data


sheen4him

Recommended Posts

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());}

Link to comment
https://forums.phpfreaks.com/topic/64008-update-query-with-blank-data/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.