title: PHP: Counter using Session Variables
body: <p>I need som help adding a value to a session variable using submit buttons. If I define the variables as 0 it won't count up, and if I don't it says:</p>
  
  <blockquote>
    <p>"Notice: Undefined index: paperbagCount in
    /home/saxon/students/20151/chwi15/www/affar3/test.php on line 52"</p>
    
    <p>"Notice: Undefined index: plasticbagCount in
    /home/saxon/students/20151/chwi15/www/affar3/test.php on line 59"</p>
  </blockquote>
  
  <pre><code>&lt;?php 
  if(!session_status() === PHP_SESSION_ACTIVE ) {
  session_start();
  $_SESSION["paperbagCount"] = 0;
  $_SESSION["plasticbagCount"] = 0; 
  } 
  session_start();
  error_reporting(-1);
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
    &lt;meta charset="utf-8"&gt;
     &lt;title&gt;Startsida&lt;/title&gt;   
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;?php 
  if(isset($_POST['addPaper'])) {
    $_SESSION["paperbagCount"]+=1;
  }
  
  if(isset($_POST['deletePaper'])) {
      if ($_SESSION["paperbagCount"] == 0) {
          $_SESSION["paperbagCount"] == 0; 
      }else{      
      $_SESSION["paperbagCount"]-=1;
      }
  }
  
  if(isset($_POST['addPlastic'])) {
    $_SESSION["plasticbagCount"]+=1;
  }
  
  if(isset($_POST['deletePlastic'])) {
      if ($_SESSION["plasticbagCount"] == 0) {
          $_SESSION["plasticbagCount"] == 0; 
      }else{      
      $_SESSION["plasticbagCount"]-=1;
      }
  }
  
  ?&gt;  
  
  &lt;form method="post"&gt;
  &lt;p&gt;&lt;label&gt;Paperbagcount&lt;/label&gt;&lt;br&gt;
  &lt;input type="submit" name="addPaper" value="+"&gt;
  &lt;?php echo $_SESSION["paperbagCount"] . "\n"; ?&gt;
  &lt;input type="submit" name="deletePaper" value="-"&gt;
  &lt;/form&gt;
  
  &lt;form method="post"&gt;
  &lt;p&gt;&lt;label&gt;Plasticbagcount&lt;/label&gt;&lt;br&gt;
  &lt;input type="submit" name="addPlastic" value="+"&gt;
  &lt;?php echo $_SESSION["plasticbagCount"] . "\n"; ?&gt;
  &lt;input type="submit" name="deletePlastic" value="-"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>