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

Edited by Ch0cu3r
Link to comment
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.