Hey guys, I'm having some trouble setting up a form to delete a specific row in my database table.
Here is the idea: I have one page that makes looping calls to MySQL for a query result, at the same time I print out the html as I need to using row->column calls for each item (pretty much display every row in the database on the web-page how I choose fit). next to each of these items I have a checkbox with a variable for the value field (an auto incrementing variable I use as the primary key id
easier shown that explained...
snippet from page described above
<?php
/*connect to and select database*/
$num_rows = mysql_num_rows($result);
$i = 0;
while ($i < $num_rows)
{
$row = mysql_fetch_array($result);
$num = $row['id'];
?>
<form action="delete.php" method="post">
...
<div><input type="checkbox" name="number" value="<? $num ?>" /><br /><? echo $num ?></div>
...
/*HTML here which displays the rest of the PHP column variables I have set up*/
<? $i++;} ?>
The action file for the previous code/form
<?php
/*connect to and select database*/
$id = $_POST[number];
mysql_query("DELETE FROM home WHERE id='$id'")
or die(mysql_error());
?>
I can see the id being echoed on the output page, but it doesn't seem to do anything when I attempt to delete it
I can change it to something like
mysql_query("DELETE FROM home WHERE category='Something'")
and it works that way I just can't seem to get a vairable to work out
if anyone has any ideas what I'm doing wrong (or even just some ideas) please let me know.