Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating table when user clicks OK button on a JavaScript alert

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?

like image 338
John Michael Rivera Avatar asked Aug 15 '26 02:08

John Michael Rivera


1 Answers

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!