update values

Discussion in 'PHP' started by jjh, Apr 14, 2007.

  1. #1
    I have two values k1 and k2 which relate to a session 1 and a session 2. When session one is active k1 is incremented and when session two is active k2 is incremented. The problem is that the new incremented values are associated only with that session so if I try to retrieve them when session = 3 to add them together I cannot, any ideas? The codes below:
    <?php
    session_start();
    $k1 = 0;
    $k2 = 0;
    if(isset($_GET['rst']))
    { session_destroy();
    header("Location: $_SERVER[PHP_SELF]");
    }
    function add()
    {
    if (!isset($_SESSION['init']))
    {
    $_SESSION['init'] = 1;
    }
    else
    {
    $_SESSION['init']++;
    }
    return $_SESSION['init'];
    }
    if ($_SESSION['init'] == 1)
    {
    $k1 ++;
    echo $k1;
    }
    elseif ($_SESSION['init'] == 2)
    {
    $k2 ++;
    echo $k2;
    }
    elseif ($_SESSION['init'] == 3)
    {
    $k3 = $k1+$k2;
    echo $k3;
    }
    ?>
     
    jjh, Apr 14, 2007 IP
  2. PresFox

    PresFox Active Member

    Messages:
    218
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    why are you starting another thread for this?
     
    PresFox, Apr 14, 2007 IP
  3. jjh

    jjh Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    made a mistake was supposed to ammend the iniitial thread
     
    jjh, Apr 14, 2007 IP