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
Share on other sites

i used what advice you gave barand, yet still my session does not log my data. does the session restart everytime the script is run? it keeps printing "asdf" because $cart[$image][0][0] keeps producing null even though data should have been set to it. ???

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.