delmardata Posted September 14, 2006 Share Posted September 14, 2006 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 Brownliedel mar data systems[email protected]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 More sharing options...
Gruzin Posted September 14, 2006 Share Posted September 14, 2006 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 More sharing options...
Gruzin Posted September 14, 2006 Share Posted September 14, 2006 and one more thing, you should use:$_SESSION instead of $SESSION Link to comment https://forums.phpfreaks.com/topic/20803-last_insert_id/#findComment-92085 Share on other sites More sharing options...
mo Posted August 3, 2007 Share Posted August 3, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.