Jump to content

[Help] Delete Multiple fields from single table


semperfi

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.

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.