<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Add Student To the Database</title>
</head>
<?php
// This script adds a students and all their information into the database so
//admins and teachers can access, update, and change the information as needed
// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
//Setup the datbase connection
include("./include/config.php");
include("./include/opendb.php");
//setup the variable names coming from the form
$student_id = 0;
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$birthday = $_POST['bdate'];
$age = $_POST['age'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$father = $_POST['father'];
$mother = $_POST['mother'];
$phone = $_POST['phone'];
$teacherid = $_POST['teacherid'];
if (isset ($_POST['submit']))
{
// Define the query.
$query = "INSERT INTO students (student_id, student_fname, student_lname, student_bdate, student_age, student_address1, student_address2, student_city, student_state, student_zip, student_father, student_mother, student_contact, teacher_id)
VALUES (0,'$firstname', '$lastname', '$birthday', '$age', '$address1', '$address2', '$city', '$state', '$zip', '$father', '$mother', '$phone', '$teacherid')";
if (!@mysql_select_db ($dbname))
{
die ('<p>Could select the database because: <b>' . mysql_error() . '</b></p>');
}
// Execute the query.
if (@mysql_query ($query))
{
echo '<p>The Student has been added to our database</p>';
echo "<input type=button value=\"Back\" onClick=\"history.go(-1)\">";
}
else
{
echo "<p>Could not add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>";
}
include("./include/closedb.php");
}
?>
<h1>Enter Students Name and Information:</h1>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table width="100%">
<!-- student id will auto increment -->
<tr>
<td>Students First Name:</td>
<td><input type="text" name="fname" size="40" /></td>
</tr>
<tr>
<td>Students Last Name:</td>
<td><input type="text" name="lname" size="40" /></td>
</tr>
<tr>
<td>Birthdate:</td>
<td><input type="text" name="bdate" size="40" /></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" size="3" /></td>
</tr>
<tr>
<td>Address 1:</td>
<td><input type="text" name="address1" size="40" /></td>
</tr>
<tr>
<td>Address 2:</td>
<td><input type="text" name="address2" size="40" /></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="city" size="40" /></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" name="state" size="40" /></td>
</tr>
<tr>
<td>Zip Code:</td>
<td><input type="text" name="zip" size="5" /></td>
</tr>
<tr>
<td>Father's Name:</td>
<td><input type="text" name="father" size="40" /></td>
</tr>
<tr>
<td>Mother's Name:</td>
<td><input type="text" name="mother" size="40" /></td>
</tr>
<tr>
<td>Contact Number</td>
<td><input type="text" name="phone" size="40" /></td>
</tr>
<tr>
<td>Teacher:</td>
<td>
<?
include("./include/config.php");
include("./include/opendb.php");
$query = 'SELECT teacher_id, teacher_name FROM teachers ORDER BY teacher_name';
$r = mysql_query($query) or exit(mysql_error());
echo '<select name="teacher">';
while ($row = mysql_fetch_assoc($r))
{
echo '<option value="' . $row['teacher_id'] . '">' . $row['teacher_name'] . '</option>';
}
echo '</select>';
include("./include/closedb.php");
?>
</tr>
<tr>
<td align="right"><input type="submit" name="submit" value="Add Student" /></td>
</tr>
</table>
<a href="view.php">View Current Students</a>
</form>
</body>
</html>