How to fix these 2 notices I recieve
<p>I have a couple of pages in my application. In the first page (create_session.php) which is below the user submits the form and goes onto the next page (QandATable.php).</p>

<pre><code>&lt;form action="QandATable.php" method="post" id="sessionForm"&gt;

&lt;p&gt;
    &lt;strong&gt;
        Your Session ID: 
    &lt;/strong&gt;
    &lt;span id="idFont"&gt;
        &lt;?php echo $id; ?&gt;
    &lt;/span&gt;
&lt;/p&gt;
&lt;input type="hidden" name="id" value="&lt;?php echo $id; ?&gt;" /&gt;

&lt;p&gt;
    &lt;strong&gt;
        Number of Sessions:
    &lt;/strong&gt; 
    &lt;input type="text" id="sessionNo" name="sessionNum" /&gt;
&lt;p&gt;
    &lt;strong&gt;
        Start Time:
    &lt;/strong&gt; 
    &lt;input type="text" id="timepicker" name="durationChosen" readonly="readonly" /&gt;

&lt;p&gt;
    &lt;input class="questionBtn" type="submit" value="Prepare Questions" name="prequestion"/&gt;
&lt;/p&gt; 

&lt;/form&gt;
</code></pre>

<p>Now if $_POST['sessionNum'] equals 1, then there is only 1 exam, but if it it is more than 1, then there are multiple exams which is where the problem occurs.</p>

<p>Lets say I wanted 2 exams and I submit the form to the QandATable.php, then the first exam has no problems, but after I finish the first exam and then submit the form (This form would submit to itself), then for the second exam, I suddenly get notices for all of the $_POST I have in the code below.</p>

<pre><code>&lt;?php
session_start();

if (isset($_POST['id'])) 
{
    $_SESSION['id'] = $_POST['id'];
}


if (isset($_POST['durationChosen'])) 
{
    $_SESSION['durationChosen'] = $_POST['durationChosen'];
}

if (isset($_POST['sessionNum'])) 
{
    $_SESSION['sessionNum'] = $_POST['sessionNum'];
}



if($_SERVER['REQUEST_METHOD'] == 'POST')

{

$time = str_replace(array(' Hrs ', ' Mins ', ' Secs'), array(':', ':', ''), $_POST['durationChosen']);

  $insert = array();

  for ($i = 1, $n = $_POST['sessionNum']; $i &lt;= $n; ++$i)
  {
    $insert[] = "'". mysql_real_escape_string( $_POST['id'] ) . ($n == 1 ? '' : $i) . "','". mysql_real_escape_string( $_POST['textWeight'] ) ."','". mysql_real_escape_string( $time ) ."'";
  }

  $sql = "INSERT INTO Session (SessionId, SessionTime, SessionDate, SessionWeight, SessionDuration, TotalMarks, ModuleId, TeacherId, Room) 
  VALUES (" . implode('), (', $insert) . ")";


  mysql_query($sql);
</code></pre>

<p>}</p>

<p>Now if I have 1 session (exam) then it works fine. The problem is that if I have 2 sessions (exams) or more. After I complete the first exam then I tell 'QandATable.php' to submiot the page to itself so the user can do the second exam on the same page. The problem is that after I submit the first exam and go on the page for the second exam, I get 2 undefined index notices for these 2 lines below which is in the php code above:</p>

<pre><code>$time = str_replace(array(' Hrs ', ' Mins ', ' Secs'), array(':', ':', ''), $_POST['durationChosen']);
</code></pre>

<p>Notice above is undefined index 'durationChosen'.</p>

<pre><code>for ($i = 1, $n = $_POST['sessionNum']; $i &lt;= $n; ++$i)
</code></pre>

<p>Notice above is undefined index 'sessionNum'.</p>

<p>Why am I getting these 2 notices and how can I fix it?</p>
