mysql - add new session product - PHP -
When a user is buying a product (say they have 3 products) and they have typed their information, then The product goes automatically in the database with position = 0.
If the user is moving away from the basket, then product overview (and buying an additional product, they now have 4 products in the basket) should be in.
I have to find out instead of adding all the products, instead of adding new product, add new product, since 3 products have already been added.
$ _ session ['inserted_ids'] = array (); $ Id = ''; If (in_array ($ id, $ _SESSION ['inserted_ids'])) {return; } Else {$ id = $ db- & gt; Insert ("INSERT command" SET name = '"$ _SESSION [' INFORMATION '] [' NAME '].' ', Address ='". $ _SESSION ['INFORMATION'] ['ADDRESS']. $ '_SESSION [' Notification '] [' Phone '],' Date ' ] ''. '', Email = ''. $ '' ['Notification'] ['email']. ", City = '". $ _SESSION [' info '] [' city ']. , $ _SESSION ['notification'] ['zipcode']. "'"); $ _SESSION [' inserted_ids'] [] = [int] $ id; # list product $ list = ''; $ Grand_total = ''; $ Res = $ db- & gt; Execute ("SQL with product_id"); while ($ line = $ res-> GetNext ()) {if ($ Execute {$ product_id '] == $ _SESSION [' inserted_ids']) {$ db- & gt; (INSERT IN order_lines SET price = '$ round_price', order_id = $ id, product_id = $ product_id, product_name = '$ Product_name', units = '$ grand_units', position = '0', date = '".database: now ()."', Item_num = ''. $ Item_num. ''; Duplicate key updates on units set = '$ Grand_units' WHERE order_id = $ id 1 border; "}"}}}}
Why do not you add your flag key to the product Check the flag before the array that indicates whether the product was inserted or not. Before inserting the product, check the flag.
If you can not do this, create another session array (call it Inserted_ids
) containing the product ID, which was inserted, and check whether There is an inserted_ids
array in product_id
.
(You just use In_Are, you do not need to loop a whole new one for that).
This should be your code:
$ _ session ['inserted_ids'] = array (); // Execute this line before everything.
insert (in_array ($ id, $ _SESSION ['inserted_ids']) {return;} $ id = $ Db- & gt; ("INSERT commands in SET name = '"$ _SESSION [' notification '] [' name '].", Address =' ". $ _SESSION ['information'] ['address'].", Date = ''. Database: Now (). '', Phone = '". (Sender ($ _ session [' Notification '] [' Phone ']) $ _SESSION [' Notice '] [' Phone ']:' '). $ '_SESSION [' alert '] [' email ']. ", City ='". $ _SESSION ['notification'] ['city']. ", Zipcode = '". $ _SESSION [' ; '$' = '$ Id; $ res = $ db- & gt; ("sql statment"); while ($ line = $ Res- & gt; GetNext ()) {$ db-> Involved ("INSERT order_lines SET value = '$ round_price', order_id = '" $ id. "', Product_id = '$ product_id', Product_name = '$ product_name', units = '$ grand_units', position = '0' , Date = '". Database :: Now ()."', Item_num = '. Item_num. "' ');}
Comments
Post a Comment