For some reason my if statements don’t work as expected.
$query = "SELECT title FROM blog";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
for ($j = 0; $j < $rows; ++$j)
{
if (isset($_POST['$j']))
{
$id = mysql_real_escape_string($_POST['id']);
$query = "DELETE FROM blog WHERE id='$id'";
mysql_query($query);
echo 'Deleted post.. ';
echo '<a href="blog.php">Click here</a>';
}
else
{
echo 'Failed!';
}
}
What happens is that “Deleted post..” and the “link” get echoed the number of rows I have in my table blog. Only one row in my table gets deleted though which is what I want. One button gets pressed each time, so shouldn’t it echo “Deleted post..” only one time and “Failed!” the rest of the times? Thanks =)
Note: I’m still new to programming, sorry if the question is stupid.
Note 2: I have many buttons on another page.. they are labeled by numbers ‘1, 2, 3’ etc.
change:
to: