Jump to content

Recommended Posts

In the following function I am turning a shopping cart into an order. The order has an order header record and many detail records. I use auto increment to assign the order id and populate the order detail records with order id using the LAST_INSERT_ID() function. Next,I want to store the order id in a session variable but $SESSION['MM_ORDER']=LAST_INSERT_ID(); does not work. what am I doing wrong. Everything else works fine in this function. How does one assign LAST INSERT_UPDATE() to a session variable?

Dennis Brownlie
del mar data systems
dennis@windowareaccounting.net





function MakeOrder($ItemId,$today,$adminid,$oe_id)
{

mysql_query("INSERT INTO inorder(order_id,admin_id,order_date) values (null,'1',NOW())");
"SELECT last_insert_id() as id_number from INCART";
// the next line does not work
$SESSION['MM_ORDER']=LAST_INSERT_ID();
mysql_query("UPDATE incart SET incart.orderid = LAST_INSERT_ID()");

mysql_query("INSERT INTO inorderdtl( order_id,part_id, price, qty) select orderid,part_id, price, qty from incart where cookieId = '" . GetCartId() . "'");


}
Link to comment
https://forums.phpfreaks.com/topic/20803-last_insert_id/
Share on other sites

Did you try to echo the last id? I mean something like this:

[code]$query = "SELECT last_insert_id() as id_number from INCART";
$result = mysql_query($query);
while($row = mysql_fetch_array($result))
echo $row['Your_feild_name'];
exit();[/code]

if it will display the last id correctly then we shoud think about sessions...
Link to comment
https://forums.phpfreaks.com/topic/20803-last_insert_id/#findComment-92084
Share on other sites

  • 10 months later...
I am trying to accomplish the exact same thing i.e update header and item table from cart. Is selecting the last insert id from the database really the best method? What if there are other inserts into your order header table at the same time, you may get the order ID for another order and not the one in your current session???
Link to comment
https://forums.phpfreaks.com/topic/20803-last_insert_id/#findComment-314891
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.