Jump to content

[SOLVED] array in a session


wds

Recommended Posts

For some reason the data is not being logged by the session. I believe it is because I am not declaring my $cart array correctly. Is $_SESSION[$cart] the incorrect way to go about this? It keeps finding $four == null meaning the data was not saved. This can be observed by the fact that it prints "asdf" instead of "fdsa". Ideas?

 

 

 

session_start();

$_SESSION[$cart];

$image = $_GET['image'];

if($cart[$image][0][0] == null){

$four = $_GET['four'];

print("asdf");

}else{

$four = $four + $_GET['four'];

print("fdsa");

}

if($cart[$image][1][0] == null){

$five = $_GET['five'];

}else{

$five = $five + $_GET['five'];

}

if($cart[$image][2][0] == null){

$eight = $_GET['eight'];

}else{

$eight = $eight + $_GET['eight'];

}

$cart = array(

$image => array(

"four" => array(

$four

),

"five" => array(

$five

),

"eight" => array(

$eight

)

)

);

 

print("<html><body>");

print("<img src=/images/" . $image . "> 4x6: " . $cart[$image]['four'][0] . " 5x8: " . $cart[$image]['five'][0] . " 8x10: " . $cart[$image]['eight'][0]);

print("</body></html>");

Link to comment
https://forums.phpfreaks.com/topic/61179-solved-array-in-a-session/
Share on other sites

<?php
session_start();

$cart = $_SESSION['cart'];                     // get session data


//
// changes to cart data
//


$_SESSION['cart'] = $cart;                      // save updated cart in session data
?>

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.