Jump to content

Session not detecting when it exists


Phaelon
Go to solution Solved by requinix,

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

Edited by Phaelon
Link to comment
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?

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.