1

I want alert the first page from the second one, for example I have the below page

<?php
    $sql = "SELECT table_id, on, off FROM tables"; //just fetching and filling my table with the info
    $stmt = mysqli_prepare($dbc, $sql);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $table_id, $on, $off);
    while(mysqli_stmt_fetch($stmt)){
?>

<tr>
<td><?php  echo '<button onclick="ShutTime('.$table_id.')" >Disable</button>'; ?><input type="hidden" id="off_<?php echo $table_id; ?>" value="<?php echo $off; ?>"></td> //this  button belongs to the code below 
</tr>   
 }

function ShutTime(table_id, off) { //these datas are sent to another script

    var off = $("#off_" + table_id).val();
    alertify.confirm("Are you sure to disable this ?",
        function(){
               $.post("ajax/deactivateTime.php", { //here
                table_id: table_id,
                off: off,

             },
            function (data, status) {
                  location.reload();
            } 
        );
  }

Here I processing them

<?php
 //This scripts receives the data's are sent by the first scripts and processes it
if(isset($_POST['table_id'])  AND isset($_POST['off']))
{
    $table_id = (int) ($_POST['table_id']);
    $off = (int) ($_POST['off']);
    $sql = "UPDATE tables SET status = 0, start_time = DEFAULT WHERE table_id = $table_id";
    $r = mysqli_query($dbc, $sql);
    //after execution I want to alert the above datas into the first script
     $res="Data Passed Successfully"; //as a Test I tried to do like this but no success
     echo json_encode($res);
}
else
{
    exit();
}

Everything is working fine, all I want is to alert the datas from deactivateTime.php to my index page, how can i achieve that?

Amanda
  • 58
  • 8

1 Answers1

0

I resolved my problem doing like

function ShutTime(table_id, off) { //these datas are sent to another script

    var off = $("#off_" + table_id).val();
    alertify.confirm("Are you sure to disable this ?",
        function(){
               $.post("ajax/deactivateTime.php", { //here
                table_id: table_id,
                off: off,

             },
            function (data, status) {
                  alert(data); //just alerting the data
                  location.reload();
            } 
        );
  }

<?php
 //This scripts receives the data's are sent by the first scripts and processes it
if(isset($_POST['table_id'])  AND isset($_POST['off']))
{
    $table_id = (int) ($_POST['table_id']);
    $off = (int) ($_POST['off']);
    $sql = "UPDATE tables SET status = 0, start_time = DEFAULT WHERE table_id = $table_id";
    $r = mysqli_query($dbc, $sql);
      $res="Data Passed Successfully";  // and junt echoing it as usual 

}

    else
    {
        exit();
    }
Amanda
  • 58
  • 8