Jump to content

Session not detecting when it exists


Phaelon

Recommended Posts

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...

Link to comment
https://forums.phpfreaks.com/topic/288230-session-not-detecting-when-it-exists/
Share on other sites

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?

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.