[Solved] How to pass a variable from a page to other in php


You can store the order number in the session. This way, it will be protected and persisted across pages.

When you insert the order in book_order.php, store it in the session:

$sql2=mysql_query(....); // inserting

if($sql2){
    $_SESSION['order_id'] = mysql_insert_id();
}

Now, in book_order2.php you can retrieve the order ID before you do the insert of the product:

$id = $_SESSION['order_id'];
// insert product with order_id = $id

In order to use PHP sessions, you must calll session_start() at the beginning of any script that makes use of the session. If you have a global/header include then you can do it there.


Side notes:

  • mysql_* is deprecated. Consider upgrading to PDO or MySQLi. This is a good PDO tutorial, especially if you’re upgrading from mysql_*.
  • Use a Prepared Statement with bound parameters instead of concatenating variables into SQL.

6

solved How to pass a variable from a page to other in php