busby Posted November 4, 2010 Share Posted November 4, 2010 hi. just a quick question about a delete link i have on a page ive made. basically with the code i have currently...nothing at all happens when i click delete...and i cant for the life of me see the problem. here is the code for the page where the delete link is. $sql=mysql_query("SELECT items.itemname, cat.catid, cat.category FROM items,cat WHERE cat.catid=items.catid"); $temp_item = ""; while($res=mysql_fetch_array($sql)) { echo "<table cellpadding='0' cellspacing='0' width='700'><tr>"; if($res['category'] != $temp_cat ) { echo "<td width='30%'>" . "<b>" . $res['category'] . "</b>" . "</td>" . "<td width='30%'><a href='delcat.php?id=$res[catid]'>Delete Category</a></td></tr>"; $temp_cat=$res['category']; } and here is the code for the delete page that should do the deleting. include_once("config_class.php"); $db = new db(); // open up the database object $db->connect(); // connect to the database //getting id of the data from url $id = $_GET['id']; //deleting the row from table $result=mysql_query("DELETE FROM cat WHERE listid=$id"); //redirecting to the display page (index.php in our case) header("Location:list.php?id=$id"); as i said nothing happens...please help anybody? Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2010 Share Posted November 4, 2010 Your links are using catid. Is catid the same as listid, which is what you are using in the DELETE query? Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130480 Share on other sites More sharing options...
busby Posted November 5, 2010 Author Share Posted November 5, 2010 Your links are using catid. Is catid the same as listid, which is what you are using in the DELETE query? erm no they are not the same...so ive made that change but it still doesnt do anything...nothing happens still...thanks for pointing that out though i didnt notice that extra error Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130482 Share on other sites More sharing options...
BlueSkyIS Posted November 5, 2010 Share Posted November 5, 2010 i suggest that you echo the SQL, then check for error during execution: $sql = "DELETE FROM cat WHERE listid = '$id'"; echo "sql: $sql <br />"; $result = mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130496 Share on other sites More sharing options...
busby Posted November 5, 2010 Author Share Posted November 5, 2010 i suggest that you echo the SQL, then check for error during execution: $sql = "DELETE FROM cat WHERE listid = '$id'"; echo "sql: $sql <br />"; $result = mysql_query($sql) or die(mysql_error()); im very new to php...i cant really do it and terminology goes right over my head...that sql checking code doesnt seem to work either... does anyone have a solution for my problem? Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130505 Share on other sites More sharing options...
BlueSkyIS Posted November 5, 2010 Share Posted November 5, 2010 please expand on "that sql checking code doesnt seem to work" Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130689 Share on other sites More sharing options...
rwwd Posted November 5, 2010 Share Posted November 5, 2010 i suggest that you echo the SQL, then check for error during execution: It will only error if there is something wrong with the sql, which there isn't - the only thing I cannot see (not to say it isn't there) is the connection handle. Did the sql statement print to screen, and did it have a value after: listid = , if it was like this: listid = '' then there was no value held in the variable. Rw Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130707 Share on other sites More sharing options...
BlueSkyIS Posted November 5, 2010 Share Posted November 5, 2010 well, you can't be sure that the sql is correct. what if $_GET['id'] is a string for some reason? that SQL would break. regardless, it is always best to 1. check for execution errors with mysql_errors() and 2. look at your SQL. It is very basic troubleshooting and very often an indicator of the problem. many problems posted here include "i know this works..." but we find out that no, this doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130722 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.