Jump to content

Session array


laqutus

Recommended Posts

How can I create a session array populate it with only one item (id), and then add other  items without overwiring the original session?

 

foreach ( $_POST as $key) { echo $key; echo "<br>"; $_session['cart'][] = $key; }?>

    <?

// Attempt to add values into session array

echo '<pre>'; print_r($_session); echo '</pre>';

?>

 

This will take in the one bit of date but is overwritten if I add anything new to it, how can I increment the session array to hold more data (like new row in mysql).

 

The problem is because I could create a new mysql table and have a temporary cart, but flushing the temporary orders (not completed) order would be a pain so I thought it better to create a session array, is this good practice?

 

Cheers

Sarah

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

Ok cool, I understand that, thanks loanwolf, but how do I increment the new index?

 

This is the bit im having trouble with, as If i make the index a variable then it does not seem to work as IO dont know how to check if the index already exists. I want the index to be numerical eg:

 

$_SESSION['1'] = "foo";

$_SESSION['2'] = "bar";

$_SESSION['3'] = "!!!";

Link to comment
https://forums.phpfreaks.com/topic/150734-session-array/#findComment-791906
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.