PHP - 仅运行一次/不更新变量的代码

So I have this program using javascript/php that is supposed to be a sort of time card system, check in, send check in date to a database, check out, it compares the dates and then it calculates the amount you've made, and sends that back to the database.

Now the problem is that the php script, that are being tiggered by javascript/ajax, only seems to run once per session, in the sense that it runs the code, then just re-runs a snapshot(?) of that code, it doesnt update with the database anymore, unless I enter a new session.

Here is the code I am using timeSystem.php: ( At the moment only using the test buttons, just have the other buttons/code still in there )

<?php
session_start();
?>
<html>
<head>


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">

    function timeCard(id) {
        if(id == "Test"){
            $(function(){
               $.get("insert.php", function(data){
                   alert(data);
               });
            });
        }
        else if(id == "Test2"){
            $(function(){
               $.get("singin.php", function(data){
                   alert(data);
               });
            });
        }
    }

</script>
<?php 
if(!$_SESSION['driverid']){
    header("location:login.php");
}
else {
?>

</head>

<body>

<h1 style="float: left" class="center">Unity Transport Authority SMS (Shift Management System)</h1> <h3>V0.2</h3>
<div style="clear: both"></div>

<table> 
    <tr>
        <td><button type="button" id="Test" onclick="timeCard(id)">Test</button></td>
        <td><button type="button" id="Test2" onclick="timeCard(id)">Test2</button></td>
        <td><form action="logout.php" mothod="post"><input type="submit"></form> </td>
    </tr>
</table>

</body>
</html>
<?php
}
?>

insert.php:

<?php
session_start();
$con=mysqli_connect(/* Removing info but this is working as intended */);
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$t = time();
$Driverno = $_SESSION['id'];

$DBDriver= mysqli_query($con,"SELECT * FROM AdminForm 
    WHERE DRIVERNO=$Driverno");

while ($row = mysqli_fetch_array($DBDriver)) {
    if ($row['CURSTATE'] == 0) {
        $sql="UPDATE AdminForm SET SINGING=$t, CURSTATE =1
        WHERE DRIVERNO=$Driverno";

        if (!mysqli_query($con,$sql)) {
            die('Error: ' . mysqli_error($con));
        }
        echo "Have a nice shift!";
    } else {
        echo "You are already signed in!";
    }
}
mysqli_close($con);
?>

singin.php:

<?php
session_start();
$con=mysqli_connect(/* Again just removed because personal info */);
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$Driverno = $_SESSION['id'];
$Payrate = 1510;

/* Select the driver from the database */
$DBDriver= mysqli_query($con,"SELECT * FROM AdminForm 
    WHERE DRIVERNO=$Driverno");

while ($row = mysqli_fetch_array($DBDriver)) {
    if ($row['CURSTATE'] == 1) { /* Checks if user is signed in */
        if ($row['RANK'] == 1) {
            $t = time();
            $DBtime=$row['SINGING'];
            echo $row['SINGING'] . "<br>";
            $time = $t - $DBtime; /*  Compare the time to the database */
            echo "Total Amount of time Worked This Session (in seconds): " . $time . "<br>";
            $Totalhours = $time + $row['TOTALHRS'];
            $Totalhours = $Totalhours / 60 / 60; /*  Conversion from seconds into hourly format */
            echo "Total Hours Worked: " . $Totalhours . "hrs";
            echo "<br>";
            $Totalpayout = $Totalhours /*/ 60 / 60*/ * $Payrate;
            echo "Total Payout is now: " . $Totalpayout . "$";

            $Paid = 0;
            $sql="UPDATE AdminForm SET TOTALHRS=$Totalhours, TOTALPAYOUT=$Totalpayout, PAID=$Paid, CURSTATE=0
            WHERE DRIVERNO=$Driverno";

            if (!mysqli_query($con,$sql)) {
              die('Error: ' . mysqli_error($con));
            }

        }
        else/* else if? */ {
            // Future code for different ranks
            echo "This is bad !";
            die();
        }
    }
    else {
        echo "Please sign in before attemping to sign out!";
    }
};

mysqli_close($con);
?>

An example of what happens is, you login then press the test2 button, which check the CURSTATE if you are on duty or not. If not it will say "Have a nice shift", and change the CURSTATE, then if you press the button once more, it wont run the code again and check if you are on duty or not, it will simply say "Have a nice shift" again.

But if you log out and back in, which resets the session, it will run the code again, and will say "You are already signed in!".

I really hope your getting what I'm talking about and can help me, and thanks for any help in advance !