dbell23 Posted April 10, 2011 Share Posted April 10, 2011 Probably easiest to explain what I am trying to do, to illustrate the impasse I have came to. I have online store With a number of products. Visitors can click on products, clicking brings details of the product came up in a frame on the right (with a field to enter the quantity), which can than be added to the shopping cart in a separate frame below it bottom right (passed using a different script (the one which I am having issues with)). So each time a product is added to the cart, three dynamic fields are passed via post script, which are named "product_name", "unit_quantity" and "unit_price" (these are all hidden fields called from a sql database based on what product the user clicked on). So for the shopping cart, I want to incorporate an associative array using the three dynamic fields described above("product_name", "unit_quantity" and "unit_price") within a session so that a number of products can be added (hence using an array rather than a variable). So shopping cart i have done so far reads: <?php session_start(); if (!isset ($product_name) && !empty($product_name)) { if (!session_is_registered("product_info")) { $pos=0; session_register("pos"); $product_info[$pos]= array ( 'product_name'=>$product_name, 'unit_quantity'=>$unit_quantity, 'product_quantity'=>$unit_quantity * $unit_price); session_register("product_info"); } ?> Not sure (as I am new to sessions, how to call the array to the screen). I have read through past threads but have not been able to found anything similar to what I am trying to achieve). Link to comment https://forums.phpfreaks.com/topic/233246-dynamic-associative-arrays-and-sessions/ Share on other sites More sharing options...
Pikachu2000 Posted April 10, 2011 Share Posted April 10, 2011 session_register() and session_is_registered() are both deprecated. Use the $_SESSION array like any other array instead. Currently this line reads "if the field is not set AND the field is not empty". I think you can see the logical problem with that . . . if (!isset ($product_name) && !empty($product_name)) Link to comment https://forums.phpfreaks.com/topic/233246-dynamic-associative-arrays-and-sessions/#findComment-1199559 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.