Jump to content

Session Array For


jimleeder123

Recommended Posts

I've got this code:

 

$f = count($_SESSION['checkoutprods']); //brings current number of products in the cart/checkout session

        for($g=0;$g<$f;$g++) { //gets each order item, so if 2 in checkout, gets the 2 products. Uses the number of items in the sessions above assigned to $f
        
            $fproduct[$g] = $_SESSION['transferproducts'.$g.''];
            
            echo "Product Test: ";
            echo $fproduct[$g];
            echo "<br /> <br />";
       
        }

 

The session $_SESSION['checkoutprods'] has whatever products have been processed. So 0 might be Margherita, and 1 might be Ham Pizza. I do a var dump on it, and it has the full names.

 

I echo out "$fproduct[$g]" but it only brings up the first leters of each item in the array (M and H in the example). Any idea how to get the full name? Once I have got this working, it will be inserted into a database table.

Link to comment
https://forums.phpfreaks.com/topic/296700-session-array-for/
Share on other sites

I have noticed that if I echo the session instead of the variable it echoes the whole name correctly. But how would I put it in this sql statement -

 

$orderitems = "INSERT INTO order_items (order_item_product, order_item_price, order_item_order_id) VALUES ('$fproduct[$g]', '$fprice', '$orderid')";
            //mysql_query($orderitems) or die(mysql_error());

 

No matter what I do, it just brings up errors probably because of the commas etc. Any help please?

Link to comment
https://forums.phpfreaks.com/topic/296700-session-array-for/#findComment-1513438
Share on other sites

Why are you still setting individual transferproducts1, transferproducts2 etc session variables? We have already suggested you not to do this.

 

Maybe you need to look back at Barands code example posted in your previous thread

http://forums.phpfreaks.com/topic/296583-auto-incremented-sessions/?p=1512996

 

 

have noticed that if I echo the session instead of the variable it echoes the whole name correctly.

Can you post what is stored in the session. Show the output of var_dump

 

 

No matter what I do, it just brings up errors probably because of the commas etc. Any help please?

It would be helpful if you could you post all error messages you are getting in full.

Link to comment
https://forums.phpfreaks.com/topic/296700-session-array-for/#findComment-1513440
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.