Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Session not detecting when it exists

    PHP Code:
    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:
    PHP 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 1print_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...
    Last edited by Phaelon; 05-04-2014 at 10:26 AM.

  2. #2
    New Coder
    Join Date
    Jan 2014
    Posts
    74
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Fixed:

    PHP Code:
    if (empty($_SESSION['cart']['product'][''.$_POST['number'].''])) {$_SESSION['cart']['product'][''.$_POST['number'].''] = array(number => $_POST['number']);} 

  3. #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,826
    Thanks
    79
    Thanked 575 Times in 562 Posts
    Quote Originally Posted by Phaelon View Post
    Fixed:

    PHP Code:
    [''.$_POST['number'].''][''.$_POST['number'].''
    Why are you using '' before and after each $_POST variable? - They are not needed as there is nothing contained within them.
    Quote Originally Posted by deathshadow View Post
    So seriously, loosen up that tie, let out the belt, and try relating to normal people on the street instead of the gentleman's club crowd.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •