wds Posted July 22, 2007 Share Posted July 22, 2007 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 More sharing options...
Barand Posted July 22, 2007 Share Posted July 22, 2007 <?php session_start(); $cart = $_SESSION['cart']; // get session data // // changes to cart data // $_SESSION['cart'] = $cart; // save updated cart in session data ?> Link to comment https://forums.phpfreaks.com/topic/61179-solved-array-in-a-session/#findComment-304506 Share on other sites More sharing options...
wds Posted July 23, 2007 Author Share Posted July 23, 2007 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 https://forums.phpfreaks.com/topic/61179-solved-array-in-a-session/#findComment-305822 Share on other sites More sharing options...
JayBachatero Posted July 23, 2007 Share Posted July 23, 2007 Try doin a print_r to see what data is in the array. print_r($cart); Link to comment https://forums.phpfreaks.com/topic/61179-solved-array-in-a-session/#findComment-305830 Share on other sites More sharing options...
wds Posted July 24, 2007 Author Share Posted July 24, 2007 Jay and Barand, i can't thank ya'll enough. I am moving along in development quite nicely now, and ya'll were very helpful. Link to comment https://forums.phpfreaks.com/topic/61179-solved-array-in-a-session/#findComment-305852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.