-2

I need the $randNum variable value after button click. but when the button is clicked the value is changed. when its echo the value its different from the table inserted value after the button clicked.

<input type="submit" class="btn btn-success btn-signin" 
       onClick="printDiv();" name="trConfirmed" id="trConfirmed" value="Print"  />

<?php
$randNum = mt_rand(10, 100000);
echo($randNum); //I want to echo the $randNum here.
?>

<?php
/* ---- IF TRANSCATION CONFIRM BUTTON CLICK--- */
if (isset($_POST['trConfirmed'])) {

    $sqlInsertInToTr = "INSERT INTO transactions (date_t,transaction_id,item_code,item_name,description,quantity,p_cost,sale_price,total_price)
                        SELECT CURDATE(),$randNum,item_code,item_name,description,quantity,p_cost,sale_price,total_price FROM tem_transaction ";
    if ($db->dbQuery($sqlInsertInToTr)) {   //need same $randNum value here
        //echo("Transaction Confirmed-----");
        echo "<meta http-equiv='refresh' content='0'>";
    }
    $deletFrmTmTr = "TRUNCATE tem_transaction";
    if ($db->dbQuery($deletFrmTmTr)) {
        //echo("deleted.........");
    }
}
?>
Pankaj Makwana
  • 3,030
  • 6
  • 31
  • 47

1 Answers1

-1

The code of the printing of value of $randNum will be executed in case of a request of POST and GET. Perhaps, you see result of GET of a request after POST request was executed. Trace in the browser how many addresses happen to php to the file to this code

Dmitry Bugrov
  • 59
  • 1
  • 3