Phaelon Posted May 4, 2014 Share Posted May 4, 2014 (edited) if (isset($_SESSION['cart']['product'][''.$_POST['number'].'']['sizes'])) Thats valid isn't it? Because that definitely exists, yet its not being detected. Does anyone know what could be causing this that I cannot see?Full code: session_start(); if (isset($_POST['cartquantity'])) { $_SESSION['cart']['product'][''.$_POST['number'].''] = array(number => $_POST['number']); if ($_POST['cartsize'] == 'S') {if (isset($_SESSION['cart']['product'][''.$_POST['number'].'']['sizes'])) {$_SESSION['cart']['product'][''.$_POST['number'].'']['sizes'] = ($_SESSION['cart']['product'][''.$_POST['number'].'']['sizes'] + $_POST['cartquantity']);} else {$_SESSION['cart']['product'][''.$_POST['number'].''] = array(sizes => $_POST['cartquantity']);}} $alert = 1; print_r($_SESSION); } Basically, it exists and each time an item is added to the cart it should be adding to the existing quantity, but instead the else is taking effect. I don't understand why... Edited May 4, 2014 by Phaelon Quote Link to comment https://forums.phpfreaks.com/topic/288230-session-not-detecting-when-it-exists/ Share on other sites More sharing options...
Solution requinix Posted May 4, 2014 Solution Share Posted May 4, 2014 It will never exist because you keep overwriting the session value in the line above. The array only has the "number" in it. Quote Link to comment https://forums.phpfreaks.com/topic/288230-session-not-detecting-when-it-exists/#findComment-1478143 Share on other sites More sharing options...
Phaelon Posted May 4, 2014 Author Share Posted May 4, 2014 Oh! Nice spot! Thanks!! Fixed: if (empty($_SESSION['cart']['product'][''.$_POST['number'].''])) {$_SESSION['cart']['product'][''.$_POST['number'].''] = array(number => $_POST['number']);} Quote Link to comment https://forums.phpfreaks.com/topic/288230-session-not-detecting-when-it-exists/#findComment-1478144 Share on other sites More sharing options...
Jacques1 Posted May 4, 2014 Share Posted May 4, 2014 This doesn't make a lot of sense. Not sure if you're trying to force the syntax of some other language on PHP. What is “number”? A string? Then it must be enclosed in quotes. You should actually see plenty of errors on the screen telling you about missing constants (because a single word in PHP is a constant). If you're not seeing those errors, then your configuration is broken. You need to set display_errors to On and error_reporting to -1 in your php.ini. What is this weird ''.$_POST['number'].'' What do you expect this to do? All user input already is a string, because HTTP doesn't know anything about PHP data types and just sends everything as a string. But even if it was an integer, why would you convert this to a string? What's the point of that? Quote Link to comment https://forums.phpfreaks.com/topic/288230-session-not-detecting-when-it-exists/#findComment-1478151 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.