Jump to content

delete where id=???


busby

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/217796-delete-where-id/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130482
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130505
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130707
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/217796-delete-where-id/#findComment-1130722
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.