I am getting undefined index on all of my $_POST after submitting
<p>I have a page here where it recieves all of the details from a previous page and posts it in the database on this page. Now lets say I have multiple exams (lets say 2 exams). When I finish the creating the first exam and then submit the form to itself, I suddenly get notices for all of the $_POSTs in the code below. Why am I getting these notices on all of my $_POST’s after my first exam? All the notices have stated that all of those indexes with a $_POST in front of it is undefined.</p>

<p>Below is my code:</p>

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

if (isset($_POST['id'])) {

$_SESSION['id'] = $_POST['id'];

}


if (isset($_POST['dateChosen'])) {

$_SESSION['dateChosen'] = $_POST['dateChosen'];

}

if (isset($_POST['timeChosen'])) {

$_SESSION['timeChosen'] = $_POST['timeChosen'];

}


$username="xxx";
$password="xxx";
$database="xxx";

mysql_connect('localhost',$username,$password);

mysql_select_db($database) or die( "Unable to select database");

  $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['timeChosen'] ) . "',' ". mysql_real_escape_string( date("Y-m-d", strtotime( $_POST['dateChosen'] ) ) ) . "'";
  }

  $sql = "INSERT INTO Session (SessionId, SessionTime, SessionDate) 
  VALUES (" . implode('), (', $insert) . ")";


  mysql_query($sql);

mysql_close();



?&gt;
</code></pre>
