PHP & MySQL function delete unchecked categories from database problem

latinflower2001

New Member
I have a PHP function that allows users to pick which categories there post should be displayed in. I want to be able to delete a users picked category from the database when they unchecked a check box. But everything I tried seemed to delete all the users categories or not work at all. Can someone help me with this problem?Here is part of my PHP function that should delete unchecked categories.\[code\]for ($x = 0; $x < count($query_cat_id); $x++){ if($query_cat_id[$x] == $cat['id']){ echo 'checked="checked"'; } else if(!isset($query_cat_id[$x])) { $mysqli = mysqli_connect("localhost", "root", "", "sitename"); $delete_id = mysqli_query($mysqli,"DELETE FROM posts_categories WHERE post_id = '" . $post_id . "'"); if (!$delete_id) { print mysqli_error($mysqli); } }}\[/code\]
 
Back
Top