Jump to content

Recommended Posts

I am trying to delete multiple fields from a single table. Here are the fields in the table;

signups_id

signup_email_address

signup_date

signup_time

 

Here is my code where I delete the data from the 'signup_email_address' and works with no issues but the other data is still there. I tried different quires but keep getting errors can someone please help with my code?

 

if(isset($_POST["unsub"]) and !empty($_POST["unsub"]))
{
	$query="delete from signups where signup_email_address='$_POST[unsub]'";	
				if(mysql_query($query,$conn))
						{

DELETE removes the whole of the matching record (row) from the table so I don't understand how the "other data is still there".

 

Also try adding  LIMIT 1 to the end of the query just to protect yourself against accidentally deleting every record.

If you're trying to clear certain fields from records, but not delete the entire record, you need to use an UPDATE query.

 

UPDATE table SET field1 = '', field2 = '', field3 = '' WHERE id = value

DELETE removes the whole of the matching record (row) from the table so I don't understand how the "other data is still there".

 

Also try adding  LIMIT 1 to the end of the query just to protect yourself against accidentally deleting every record.

 

Sorry should of mentioned that it is for a unsubscribe input field where the user inputs his email address for unsubscribing ( delete his/her email from DB ). So which should I use delete or update? 

Depends.  If you have a seperate table for subscriptions that's linked to your members table, use delete.  if you're just using a members table with a field that determines whether or not they're subscribed, use update so the member's account doesn't get deleted.

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.