giraffemedia Posted August 13, 2008 Share Posted August 13, 2008 Hi, i'm having problems getting my delete query to work on an edit form. I'm using array_diff to work out the different values returned from a row of checkboxes that were pre populated from existing values in the database. This works fine and I have echoed the results to check that the correct values are returned - which they are. The next part of the form adds new values that don't already exist and once that is done I want to delete the values that are currently in the db but are no longer needed. Here is what I have... // Use array_diff to check all differences in the two arrays of issues. If not NULL define the two variables for add and delete. If no changes have been made declare both variables NULL if ($new_issue_list != NULL) { $delete = array_diff($issues, $new_issue_list); $add = array_diff($new_issue_list, $issues); } else { $add = NULL; $delete = NULL; } // Check if the $add variable is NULL. If it is don't do anything with the varibale, if it isn't run the mysql INSERT query if ($add == NULL) { } else { foreach( $add as $add_key => $add_value) { mysql_query("INSERT INTO issues_booked (ib_id, ib_issue_number, ib_booking_form_number) VALUES ('','$add_value', '$bf_record')"); } } // Check if the $delete variable is NULL. If it is don't do anything with the varibale, if it isn't run the mysql DELETE query if ($delete == NULL) { } else { foreach( $delete as $key => $value) { mysql_query("DELETE FROM issues WHERE ib_issue_number = '$value' AND ib_booking_form_number = '$bf_record'"); } } Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/119463-solved-mysql-delete-problems/ Share on other sites More sharing options...
spasme Posted August 13, 2008 Share Posted August 13, 2008 I'm not sure i understood exactly what you need done... If you use mysql_query("DELETE FROM ...") -- this DELETES the entire row. If you need to set certain fields in your table as blank or something use something like this: $result = mysql_query("UPDATE issues SET field_name='$variable' WHERE id='$id' ") or die ("Could not read data because ".mysql_error()); or an other idea: try usgin $value = $_GET[value] or $value = $_POST[value] dependin on how the value is read, from a post or URL same goes for $bf_record Cheers Quote Link to comment https://forums.phpfreaks.com/topic/119463-solved-mysql-delete-problems/#findComment-615396 Share on other sites More sharing options...
giraffemedia Posted August 13, 2008 Author Share Posted August 13, 2008 I'm not sure i understood exactly what you need done... If you use mysql_query("DELETE FROM ...") -- this DELETES the entire row. That's what I want to do spasme. Each issue is held in a row and I want to delete the issues that are no longer needed. Regards James Quote Link to comment https://forums.phpfreaks.com/topic/119463-solved-mysql-delete-problems/#findComment-615397 Share on other sites More sharing options...
spasme Posted August 13, 2008 Share Posted August 13, 2008 ok, so you need to delete the entire row... can you echo $value and $bf_record? Quote Link to comment https://forums.phpfreaks.com/topic/119463-solved-mysql-delete-problems/#findComment-615401 Share on other sites More sharing options...
giraffemedia Posted August 13, 2008 Author Share Posted August 13, 2008 Yes, both echo correctly I've sorted it - had a letter missing on one of the queries. Doh!! Thanks for your help. James Quote Link to comment https://forums.phpfreaks.com/topic/119463-solved-mysql-delete-problems/#findComment-615411 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.