I have a MySQL database and with a php function i made a table is created to view the content.
Now i have an image (a little red cross). Now i want that if the user click’s on the image a delete query is executed. But i don’t know how.
$column = array_keys($array[0]);
echo "<table border='1'>";
echo "<tr>";
foreach($column as $title)
{
echo "<td width='100px'>$title</td>";
}
echo "</tr>";
echo "<tr>";
foreach($array as $row)
{
foreach($row as $item)
{
echo "<td>$item</td>";
}
echo '<td><img src="delete_button.png value="'.$row['id'].'"" /></td>'; //the button and the id as value
echo "</tr>";
}
echo "</table>";
You would have to put a link on the image as such
And then in your delete.php file or whatever other script you put, you retrieve the id with
And you execute your query.
I hope your site is secured and that not everyone or every crawler and hit that link though, make sure it is safe, and I would recommend adding a confirm box at the very least.