<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Response for Faculty Input Form</title>
</head>

<body>

<br />
<br />
<br />
<br />
<h2>RESPONSE FROM FACULTY INPUT FORM </h2>
<br />
<br />
<br />
<br />

<?php

// Get values from form
$name = $_POST['faculty_last_name'];
$bdate = $_POST['faculty_bdate'];
$subject = $_POST['faculty_subject'];
$gender = $_POST['faculty_gender'];
$ext = $_POST['faculty_ext'];

echo<<<_END
$name
$bdate
$subject
$gender
$ext
_END;

// Check values from form

if (!$name)
echo "You must have the faculty name set to a value";
else
{

// Connect to MySQL
require_once 'login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!db_server) die("unable to connect to MySQL:" . mysql_error());

// Connect to the DB
mysql_select_db($db_database)
or die("Unable to connect to database: " . mysql_error());

// Prepare variables
$name = FixData($name);
$subject = FixData($subject);
$bdate = FixData($bdate);
$gender = FixData($gender);
$ext = FixData($ext);

// Set up the Query strings
$table = "faculty_form";
$add_query = "INSERT into $table VALUES('$name', '$bdate','$subject', '$gender', '$ext')";
$list_query = "SELECT * from $table";

// Execute the Query
$result = mysql_query($add_query);
if (!$result) die("Database Insert failed: " . mysql_error());

// Process the results and create the values for webpage
if ($result)
{
echo "<p>row added: $name, $bdate, $subject, $dGender, $ext</p>\n";
}
else
{
echo " <p>ERROR in adding record.</p>\n";
die("unable to Insert into MySQL:" . mysql_error());
}

$result = mysql_query($list_query);
if (!$result)
{
echo " <p>ERROR accessing the table.</p>\n";
die("unable to select data from MySQL:" . mysql_error());
}

$rows = mysql_num_rows($result);

for ($j = 0; $j < $rows; ++$j)
{
$row = mysql_fetch_array($result); // can index with db col names
//$row = mysql_fetch_row($result); // must use index numbers
echo<<<_END
<h4>
$row[0] $row[1] $row[subject] $row[gender] x$row[ext]
</h4>
_END;

}

mysql_close($db_server);
}

function FixData($var)
{
$var = trim($var);
if (get_magic_quotes_gpc())
$var = stripslashes($var);
$var = mysql_real_escape_string($var);
$var = htmlentities($var);
return $var;
}

?>

</body>
</html>