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
Share on other sites

You're probably missing a space somewhere... echo the final query and see, or post the mysql_error().  BTW, it's better to update via a UID than user/pass in plaintext all the time.  As for 2nd question, I have no idea hwat you mean.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.