So, I have a PHP that will echo a JavaScript alert() message when a record is inserted on a table.
Also, I have a trigger JavaScript for triggering the PHP in a given time. Here is my code for trigger JavaScript:
/*refresh every 1 minute*/
setInterval(function () {
$.ajax({
url: 'check.php',
success: function (result) {
// console.log(result);
alert('Another ticket from API');
}
});
}, 1000);
Here is a sample of my PHP:
$query="SELECT TOP(1)* FROM tblname WHERE Status=0";
$que=mssql_query($query);
if($que>0){
echo "<script type='text/javascript'>alert('Record inserted on a table') </script";
}
So what I want is when an alert() message pop-up is displayed and the user clicks OK, the Status=0 in the table will be updated to Status=1 so it won't show again.
Any idea how to do this?
You can have multiple lines in your <script>, right? First line would call alert, second would call your PHP to update the database.
if($que>0){
echo "<script type='text/javascript'>alert('Record inserted on a table'); callDatabaseToUpdateStatusToZero(); </script";
}
Here callDatabaseToUpdateStatusToZero() would be a JavaScript function that makes a call to a PHP file to update the status.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With