Hi, I am receiving this error and I'm tearing my hair out because I cannot seem to fix it. It isn't even part of the final system I just want to test this functions ability to DELETE categories if they already exist but its just throwing up problem after problem that I can't seem to get to the source of.
For the sake of this post I've removed my echo statements. I'm deliberately passing numbers to control the effects but its just bizarre. Posting 5 as I am now, it WAS just throwing up a "Use of undefined constant mysql_error". I removed the error reporting to get beyond that part but there is still an error there it doesn't like.
Up until the data is entered however, post_ID shows up as 5 so the information at least is being correctly given but mySQL doesn't like it.
Then I get to my delete function which compares an array of the current IDs from the database against the new ones. It is meant to remove the difference but $deleteCat has no content after using array_diff. I've tried a count and echoing it and it gives off '0' and "Array". In the database they are stored as INT so I'm assuming they're the same type but it's finding no differences so it won't delete anything.
I'm honestly stumped. Even if I go back to where this function is called, which passes as $post_ID "$post_ID = (int) mysql_insert_id();" and change that to 5 (my test post) it still throws up an error. I've tried $post_ID = (int) 5;
I've also echoed the results from the database and it is retrieving the CURRENT ids correctly.
I really just don't know what the issue is, it is probably (hopefully) something simple but it just doesn't want to work for me. I've been at this for about 3 hours. Anyone see what the issue is?
Code PHP:function setRelationships($post_ID, $post_categories) { $post_categories = array (1, 3, 8, 9); $post_ID = 5; if ( !is_array($post_categories) ) { $post_categories = array($post_categories); } $result = mysql_query("SELECT category_id FROM relationships WHERE post_id = $post_ID"); if($result) { while($row = mysql_fetch_array($result)){ $currentCategories = array($row['category_id']); } } else { $currentCategories = array(); } foreach ((array) $post_categories as $term) { if (!strlen(trim($term)) ) continue; mysql_query("INSERT INTO relationships (post_id, category_id) VALUES ($post_ID, $term)"); } updateCategoryCount($post_categories); //UPDATE COUNT OF CATEGORIES if($currentCategories) { $deleteCat = array_diff($currentCategories, $post_categories); if($deleteCat) { $deleteIN = "'" . implode("','", $deleteCat)."'"; mysql_query("DELETE FROM relationships WHERE post_id=$post_ID AND category_id IN ($deleteIN)"); } } }



Reply With Quote



Bookmarks