*/
    if (strlen($d) == 1) {
        $d = 0 . $d;
    }
    $date = $y . "-" . $m . "-" . $d;
    if ($sampm == "PM") {
        $sh = $sh + 12;
    }
    $st = $sh . ":" . $sm;
    if ($eampm == "PM") {
        $eh = $eh + 12;
    }
    $et = $eh . ":" . $em;
    $endDate = $date . "T" . $et . ":00";
    $date = $date . "T" . $st . ":00";
    $code = randomCodeGenerator(25);
    $sql = "select ID From K12_TEACHER where Email = '" . $_SESSION['email'] . "'";
    $result = mysqli_query($con, $sql) or die(mysqli_error($con));
    $tid = mysqli_fetch_array($result);
    $sql = "call K12_EVENTS_INSERTEVENT('" . $t . "', '" . $date . "', '" . $endDate . "', '" . $tid[0] . "', '" . $code . "', '" . $desc . "')";
    // may want to use an autoincrement value for the eventID rather than randomly generated code
    $result = mysqli_query($con, $sql) or die(mysqli_error($con));
    //a non-select statement query will return a result indicating if the
    if ($result) {
        $msg = "<b>Your information is entered into the database. </b>";
    }
}
?>


<style>
 //$sql = "select count(*) as c from K12_TEACHER where Email = '" . $em. "'";
 $sql = "call K12_TEACHER_COUNTFORREGISTRATION('" . $em . "');";
 // use stored procedure
 //$sql = "call K12_TEACHER_COUNTFORREGISTRATION($em)";    // use stored procedure
 $result = mysqli_query($con, $sql) or die("Error in the consult.." . mysqli_error($con));
 //send the query to the database or quit if cannot connect
 $count = 0;
 $field = mysqli_fetch_object($result);
 //the query results are objects, in this case, one object
 $count = $field->c;
 $result->close();
 $con->next_result();
 if ($count != 0) {
     Header("Location:login.php");
 } else {
     $code = randomCodeGenerator(50);
     //$sql = "insert into K12_TEACHER values('', '".$em."', '".$fn."', '".$ln."', '".$s."', '".$e."', '".$b."', '".$pw."', 'no', '".$code."', '3')";
     $sql = "call K12_TEACHER_INSERTNEWTEACHER('" . $em . "', '" . $fn . "', '" . $ln . "', '" . $s . "', '" . $e . "', '" . $b . "', '" . $pw . "', 'no', '" . $code . "');";
     // stored procedure
     $result = mysqli_query($con, $sql) or die(mysqli_error($con));
     //a non-select statement query will return a result indicating if the
     if ($result) {
         $msg = "<b>Your information is entered into the database. </b>";
     }
     //direct to the next page if necessary
     //If all fields are valid, a random code is generated and emailed to the user's given email.
     $subject = "Email Activation";
     $body = "Your code is " . $code . "<br /><br />Please finish registration by inputting your code at http://corsair.cs.iupui.edu:20741/studentOutreach/activation.php?c=" . $code;
     $mailer = new Mail();
     if ($mailer->sendMail($em, $fn, $subject, $body) == true) {
         //This essentially logs the user in by telling the session the email of the user.