baconDelta
01-27-2012, 10:56 PM
so i'm in the process of making a cms for some mods to be able to remove certain rows from a db.
the list of rows displays correctly, and i got the checkbox idea for each row from this thread,
http://www.dynamicdrive.com/forums/showthread.php?t=43923
and changed everything appropriately(or so i think) but when the delete button is pushed absolutely nothing happens.
here's what the list looks like:
<?php
$query = "SELECT *
FROM store
ORDER BY TIME DESC";
$result = mysql_query($query, $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
echo '<br /><b><u>LATEST UPLOADS:</u></b><br /><br />';
echo '<table border=1 align=center cellpadding=5>';
echo '<tr><th>URL OF UPLOAD</th><th>FROM IP</th><th>TIME</th>';
echo '<th><input name="delete" type="submit" id="delete" value="Delete" method="POST"></th></tr>';
while ($row = mysql_fetch_array($result))
{
$link = "../".$row["url"];
echo "<tr>";
echo "<td><a href='{$link}'>{$row["url"]}</a></td>";
echo "<td>{$row["IP"]}</td>";
echo "<td>{$row["TIME"]}</td>";
echo "<td><input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox[]\" value=\"{$row["id"]}\" /></td>";
echo '</tr>';
}
if(isset($_POST['delete']))
{
if (count($_POST['checkbox']) > 0) {
foreach ($_POST['checkbox'] as $del_id) {
$sql = "DELETE FROM store WHERE id=' " . $del_id . " ' ";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows($result) > 0) echo 'Selected data rows Deleted';
}
}
}
?>
my code is slightly different than the link above in that i'm echoing my table in php.
i see that he is making a $count variable at the top but it doesn't look like it's used in deleting so i don't think i need this. i may be completely wrong lol
but anyway nothing happens on pressing the delete button, any ideas why?
the list of rows displays correctly, and i got the checkbox idea for each row from this thread,
http://www.dynamicdrive.com/forums/showthread.php?t=43923
and changed everything appropriately(or so i think) but when the delete button is pushed absolutely nothing happens.
here's what the list looks like:
<?php
$query = "SELECT *
FROM store
ORDER BY TIME DESC";
$result = mysql_query($query, $connection);
if (!$result) {
die("Database query failed: " . mysql_error());
}
echo '<br /><b><u>LATEST UPLOADS:</u></b><br /><br />';
echo '<table border=1 align=center cellpadding=5>';
echo '<tr><th>URL OF UPLOAD</th><th>FROM IP</th><th>TIME</th>';
echo '<th><input name="delete" type="submit" id="delete" value="Delete" method="POST"></th></tr>';
while ($row = mysql_fetch_array($result))
{
$link = "../".$row["url"];
echo "<tr>";
echo "<td><a href='{$link}'>{$row["url"]}</a></td>";
echo "<td>{$row["IP"]}</td>";
echo "<td>{$row["TIME"]}</td>";
echo "<td><input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox[]\" value=\"{$row["id"]}\" /></td>";
echo '</tr>';
}
if(isset($_POST['delete']))
{
if (count($_POST['checkbox']) > 0) {
foreach ($_POST['checkbox'] as $del_id) {
$sql = "DELETE FROM store WHERE id=' " . $del_id . " ' ";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows($result) > 0) echo 'Selected data rows Deleted';
}
}
}
?>
my code is slightly different than the link above in that i'm echoing my table in php.
i see that he is making a $count variable at the top but it doesn't look like it's used in deleting so i don't think i need this. i may be completely wrong lol
but anyway nothing happens on pressing the delete button, any ideas why?