pneudralics Posted April 23, 2009 Share Posted April 23, 2009 Can't figure why php is deleting by ascending instead of the data that has the delete form. If I have ids 1, 2, 3 showing and try to delete 3, php will delete 1 or if I try to delete 2 php will delete 1. // While there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // Get date reading fields $id = $list['id']; $title = $list['title']; $image = $list['image']; $category = $list['category']; echo "<div id=\"displaycolumn\">"; if ($numcolsprinted == $numcolszero) { echo "<table align=\"center\"><tr>"; $numcolsprinted = 0; } if ($numcolsprinted == $numcols) { echo "</tr><tr>"; $numcolsprinted = 0; } echo "<td align=\"center\" width=\"250\"> <b>$title</b> <br /> <img src=\"$websiteurl/backgrounds/$category/$image\" alt=\"$id\" width=\"200\" height=\"200\" style=\"border:solid;border-color:#000000;\" /><br /> <form action=\"backgroundsdelete.php\" name=\"deleteform\" method=\"post\"> <input type=\"submit\" name=\"delete\" value=\"$id\" /> </form> </td>\n"; // Bump up row counter $numcolsprinted++; } // End while loop ?> <div align="center"> <?php // delete database if (isset($_POST['delete'])) { $delete = "DELETE FROM background WHERE id = \"$id\" LIMIT 1"; mysql_query("$delete"); //delete image $deleteimage = "$backgroundsfolder\\$category\\$image"; unlink("$deleteimage"); echo "<font color=\"red\">Background $id deleted.</font>"; } // delete end ?> </div> Link to comment https://forums.phpfreaks.com/topic/155287-why-is-php-deleting-by-asc-instead-of-the-selected-data/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 23, 2009 Share Posted April 23, 2009 Remove the double quotes from around the $id and unless you have multiple rows with the same id and you only want to delete one of them, the LIMIT 1 is pointless. Try this - $delete = "DELETE FROM background WHERE id = $id"; If that does not work correctly, do a "view source" of your form in the browser and make sure the values are correct. Link to comment https://forums.phpfreaks.com/topic/155287-why-is-php-deleting-by-asc-instead-of-the-selected-data/#findComment-816997 Share on other sites More sharing options...
pneudralics Posted April 23, 2009 Author Share Posted April 23, 2009 Still doesn't work. In view source the value of the delete input has the same id as the image. Link to comment https://forums.phpfreaks.com/topic/155287-why-is-php-deleting-by-asc-instead-of-the-selected-data/#findComment-817004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.