I am trying to have an UPDATE query run when I click an icon on a web page. I just need to have the image have the proper call function in onclick to run the mysql from the corresponding php file.
The page already loads and displays all values in a list associated with $show_id, so that variable is already being pulled from the web page in to the php code. I just need to be able to pull that variable in to the query below and have it run when I click on the icon associated with it.
This is code I have in the php file:
function retired()
{
if(strlen(($_POST['retired'])) > 0){
$sql = "UPDATE ttb_books SET status_id = '2' WHERE show_id='$show_id'";
$db = new database();
$db->myquery($sql, 1);
header('Location:books.php?show_id=$show_id');
die();
}
}
This is the current image/form html:
<form method="post" action="books.php?show_id={show_id}">
<input type="image" src="../images/icon-Red_Light.png" width="20" name="retired" alt="Set status to Out of Print" title="Set status to Out of Print" onclick="return confirm('Set ALL status to Out of Print?')">
<input name="shid1" type="hidden" id="shid1" value="{show_id}" />
</form>
So the onclick would call the function with that mysql string and update all items in the list accordingly.
Maybe you can do this on that icon :
At first, you need to put your $show_id, call it from your DB and put it to the link below
<a href="actionsite.php?update=show_id">
<img src="../images/icon-Red_Light.png" width="20" name="retired" alt="Set status to Out of Print" title="Set status to Out of Print"/>
</a>
And this on the actionsite.php
:
$show_id = mysqli_real_escape_string($_GET['update']);
$query = $db->query("UPDATE ttb_books SET status = 37 WHERE show_id = '$show_id'");
echo "<script>window.history.back();</script>";
Hope this can help you...