semperfi Posted June 5, 2011 Share Posted June 5, 2011 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)) { Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/ Share on other sites More sharing options...
DaiLaughing Posted June 5, 2011 Share Posted June 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/#findComment-1225383 Share on other sites More sharing options...
lordshoa Posted June 5, 2011 Share Posted June 5, 2011 Should the query not be like that ? * = everything $query=("DELETE `*` FROM `signups` WHERE `signup_email_address` = "'.$_POST['unsub'].'" AND `limit` = '1' "); Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/#findComment-1225428 Share on other sites More sharing options...
Pikachu2000 Posted June 5, 2011 Share Posted June 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/#findComment-1225516 Share on other sites More sharing options...
ShoeLace1291 Posted June 6, 2011 Share Posted June 6, 2011 $delete_array = array(1, 5, 8, 10) //List of ids to delete foreach($delete_array as $id){ $query = mysql_query("DELETE FROM table WHERE id = ".$id." ) With this, rows 1,5, 8, and 10 will be deleted. Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/#findComment-1225760 Share on other sites More sharing options...
semperfi Posted June 6, 2011 Author Share Posted June 6, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/#findComment-1225764 Share on other sites More sharing options...
ShoeLace1291 Posted June 7, 2011 Share Posted June 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238459-help-delete-multiple-fields-from-single-table/#findComment-1226289 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.