title: PHP: Notice: "Undefined index" when using $_SESSION
body: <p>I am using PHP and I return this value: <code>$_SESSION['sessionNum']</code> and I get an error:</p>
  
  <pre><code>Notice: Undefined index: sessionNum.
  </code></pre>
  
  <p>What does this error mean?</p>
  
  <p>Here is My buggy PHP code for the referring page (create_session2.php)</p>
  
  <pre><code>&lt;?php
    session_start();
  ?&gt;
  &lt;script type="text/javascript"&gt;
    function validation() {
      var isDataValid = true;
      var sessionNoO = document.getElementById("sessionNo");            
      var errSessionNoMsgO = document.getElementById("sessionNoAlert")
  
      if(sessionNoO.value == ""){
        errSessionNoMsgO.innerHTML = "Please Set the Number of Sessions";
        isDataValid = false;
      } 
      else if (sessionNoO.value == 0){
        errSessionNoMsgO.innerHTML = "Number of Sessions Must be More than 0";
        isDataValid = false;
      } 
      else {
        errSessionNoMsgO.innerHTML = "";
      }   
      return isDataValid;
    }
  
    function showConfirm(){
      var confirmMsg=confirm(
        "Make sure that your details are correct, once you proceed after " +
        "this stage you would not be able to go back and change any " +
        "details towards your Session." + 
        "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );
  
      if (confirmMsg==true){
        submitform();   
      }
    }
  
    function submitform(){
      var sessionFormO = document.getElementById("sessionForm");
      sessionFormO.submit();
    }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;h1&gt;CREATING A NEW SESSION&lt;/h1&gt;
    &lt;br/&gt;
    &lt;form action="QandATable2.php" 
      method="post" id="sessionForm"&gt;
      &lt;p&gt;&lt;strong&gt; Number of Sessions you Require:&lt;/strong&gt; 
        &lt;input type="text" 
          id="sessionNo" 
          name="sessionNum" 
          onkeypress="return isNumberKey(event)" 
          maxlength="5" /&gt;&lt;br/&gt;
        &lt;span id="sessionNoAlert"&gt;&lt;/span&gt;
      &lt;/p&gt;
      &lt;p&gt;&lt;input class="questionBtn" 
        type="submit" 
        value="Prepare Questions" 
        name="prequestion" onClick="myClickHandler(); return false;"/&gt;
      &lt;/p&gt;
      &lt;!-- Prepare Questions here--&gt;
    &lt;/form&gt;
  
    &lt;script type="text/javascript"&gt;
      function myClickHandler(){ 
        if(validation()){ 
          showConfirm(); 
        } 
      }
    &lt;/script&gt;
    &lt;/body&gt;
  </code></pre>
  
  <p>Below is code for the current page (QandATable2.php)</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    function showConfirm(){
      var confirmMsg=confirm(
        "Make sure that your details are correct, once you proceed after " +
        "this stage you would not be able to go back and change any details " +
        "towards Questions, Options and Answers for your Session." + 
        "\n" + "\n" + "Are you sure you want to Proceed?" + "\n" );
      if (confirmMsg==true){
        submitform();   
      }
    }
  
    function submitform(){
      var sessionMarksO = document.getElementById("sessionMarks");
      sessionMarksO.submit();
    }
  
  &lt;/script&gt;
  
  &lt;body&gt;
    &lt;form id="enter" 
      action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" 
      method="post" onsubmit="return validateForm(this);" &gt;
       &lt;p&gt;
         &lt;input id="submitBtn" name="submitDetails" 
           type="submit" 
           value="Submit Details" 
           onClick="myClickHandler(); return false;" /&gt;
  
       &lt;/p&gt;
     &lt;/form&gt; 
  
     &lt;script type="text/javascript"&gt;
       function myClickHandler(){
         if(validation()){
           showConfirm();
         }
       }
     &lt;/script&gt;
  
     &lt;?php
       session_start();
  
       $outputDetails = "";
       $outputDetails .= "
       &lt;table id='sessionDetails' border='1'&gt;
       &lt;tr&gt;
         &lt;th&gt;Number of Sessions:&lt;/th&gt; 
         &lt;th&gt;$_SESSION['sessionNum'] = $_POST['sessionNum'];&lt;/th&gt;
       &lt;/tr&gt;";
       $outputDetails .= "        &lt;/table&gt;";
  
       echo $outputDetails;
     ?&gt; 
  </code></pre>