initial commit

This commit is contained in:
Vicky Steeves 2018-02-17 20:28:11 -05:00
commit 59e65e52e2
10 changed files with 698 additions and 0 deletions

136
ClassRoster.php Normal file
View File

@ -0,0 +1,136 @@
<?php # Script 9.5 - ClassRoster.php #2
// This script performs an INSERT query to add a record to the users table.
$page_title = 'Class Roster';
include ('includes/header.html');
// Check for form submission:
// echo $_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between post and get?
require ('./mysqli_connect.php'); // Connect to the db.
$errors = array(); // Initialize an error array.
// Check for an courese information:
if (empty($_POST['course_name'])) { //$_POST is a global variable. empty() method determines whether a variable is considered to be empty.
$errors[] = 'You forgot to enter the course name';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['course_name'])); //mysqli_real_escape_strin()escapes special characters in a string for use in an SQL statement.
$sn = mysqli_real_escape_string($dbc, trim($_POST['semester_name']));
$sy = mysqli_real_escape_string($dbc, trim($_POST['semester_year']));
}
if (empty($errors)) { // If there is no errors. If everything's OK.
// Make the query:
$q = "SELECT CouLongName, CONCAT(SemesterName, SemesterYear) as SemesterInf, CONCAT(StuLastName, ', ', StuFirstName) as name from Students, Semesters, Courses, StudentClass, ScheduleOfClasses
WHERE Students.StudentID=StudentClass.StudentID AND
ScheduleOfClasses.CourseID=Courses.CourseID AND
ScheduleOfClasses.ScheduleID=StudentClass.ScheduleID AND
ScheduleOfClasses.SemesterID=Semesters.SemesterID AND
CouLongName='$fn' AND Semesters.SemesterName='$sn' AND Semesters.SemesterYear='$sy'";
$r = @mysqli_query ($dbc, $q); // Run the query.
$num = mysqli_num_rows($r);
if ($num > 0) { // If it ran OK, display the records
// Print how many users there are:
echo "<p>There is the information for the course you are looking for.</p>\n";
// Table header.
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr><td align="left"><b>Course Name</b></td><td align="left"><b>Semester</b></td><td align="left"><b>Student Name</b></td></tr>';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //MYSQLI_ASSOC makes the returned array assortative.
echo '<tr><td align="left">' . $row['CouLongName'] . '</td><td align="left">' . $row['SemesterInf'] . '</td><td align="left">' . $row['name'] . '</td></tr>
';
}
echo '</table>'; // Close the table.
}
else { // If it did not run OK.
// Public message:
echo '<h1>Error</h1>
<p class="error">There is no course roster match with the information you provided</p>';
}
}
mysqli_close($dbc); // Close the database connection.
} // End of the main Submit conditional.
?>
<form class="form-horizontal" action="show_roster.php" method="post">
<fieldset>
<legend>Class Roster</legend>
<div class="form-group">
<label for="course_name" class="col-lg-2 control-label">Course Name</label>
<div class="col-lg-10">
<input class="form-control" placeholder="Course Name" autocomplete="off" type="text" name="course_name" id="course_name" size="15" maxlength="50" value="<?php if (isset($_POST['course_name'])) echo $_POST['course_name']; ?>" />
</div>
</div>
<!-- SEMESTER -->
<div class="form-group">
<label for="semester" class="col-lg-2 control-label">Semester Name</label>
<div class="col-lg-10">
<select class="form-control" id="semester">
<option value="semester" selected>--Semester--</option>
<option value="Fall">Fall</option>
<option value="Spring">Spring</option>
<option value="Summer">Summer</option>
</select>
</div>
</div>
<!-- YEAR -->
<div class="form-group">
<label for="year" class="col-lg-2 control-label">Semester Year</label>
<div class="col-lg-10">
<select class="form-control" id="year">
<option value="year" selected>--Year--</option>
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
<option value="2003">2003</option>
<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
</div>
</div>
<!-- submit button -->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-primary">Show Class Roster</button>
</div>
</div>
</fieldset>
</form>
<?php include ('includes/footer.html'); ?>

1
README.md Normal file
View File

@ -0,0 +1 @@
# Helping students make their first PHP-MySQL web form

152
employee.php Normal file
View File

@ -0,0 +1,152 @@
<?php # Script 9.5 - register.php #2
// This script performs an INSERT query to add a record to the users table.
$page_title = 'New Lecturer';
include ('includes/header.html');
// Check for form submission:
// echo $_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//echo '1';
require('mysqli_connect.php'); // Connect to the db.
//echo '2';
$errors = array(); // Initialize an error array.
//echo '3';
// Check for a first name:
if (empty($_POST['first_name'])) {
echo 'You forgot to enter your first name.';
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['first_name']));
}
// Check for a last name:
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['last_name']));
}
// Check for an email address:
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = mysqli_real_escape_string($dbc, trim($_POST['email']));
}
if (empty($_POST['gender'])) {
$errors[] = 'You forgot to enter your gender.';
} else {
$g = mysqli_real_escape_string($dbc, trim($_POST['gender']));
}
if (empty($_POST['ssn'])) {
$errors[] = 'You forgot to enter your ssn.';
} else {
$s = mysqli_real_escape_string($dbc, trim($_POST['ssn']));
}
if (empty($errors)) { // If everything's OK.
// Register the lecturer in the database...
// Make the query:
$q = "INSERT INTO Lecturers (LecLastName, LecFirstName, LecEmail, Gender, SSN) VALUES ('$ln', '$fn', '$e', '$g', '$s')";
$r = @mysqli_query ($dbc, $q); // Run the query.
if ($r) { // If it ran OK.
// Print a message:
echo '<h1>Thank you!</h1>
<p>You are now in the database.</p><p><br /></p>';
} else { // If it did not run OK.
// Public message:
echo '<h1>System Error</h1>
<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
// Debugging message:
echo '<p>' . mysqli_error($dbc) . '<br /><br />Query: ' . $q . '</p>';
} // End of if ($r) IF.
mysqli_close($dbc); // Close the database connection.
// Include the footer and quit the script:
include ('includes/footer.html');
exit();
} else { // Report the errors.
echo '<h1>Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) { // Print each error.
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
} // End of if (empty($errors)) IF.
mysqli_close($dbc); // Close the database connection.
} // End of the main Submit conditional.
?>
<form class="form-horizontal" action="show_roster.php" method="post">
<fieldset>
<legend>Register</legend>
<div class="form-group">
<label for="first_name" class="col-lg-2 control-label">First Name:</label>
<div class="col-lg-10">
<input class="form-control" placeholder="First Name" autocomplete="off" name="first_name" id="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" />
</div>
</div>
<div class="form-group">
<label for="last_name" class="col-lg-2 control-label">Last Name:</label>
<div class="col-lg-10">
<input class="form-control" placeholder="Last Name" autocomplete="off" type="text" name="last_name" id="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />
</div>
</div>
<div class="form-group">
<label for="email" class="col-lg-2 control-label">Email Address:</label>
<div class="col-lg-10">
<input class="form-control" placeholder="Email Address" autocomplete="off" type="text" name="email" id="email" size="20" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
</div>
</div>
<div class="form-group">
<label for="gender" class="col-lg-2 control-label">Gender:</label>
<div class="col-lg-10">
<input class="form-control" placeholder="Gender" autocomplete="off" type="text" name="gender" id="gender" size="10" maxlength="20" value="<?php if (isset($_POST['gender'])) echo $_POST['gender']; ?>" />
</div>
</div>
<div class="form-group">
<label for="ssn" class="col-lg-2 control-label">SSN:</label>
<div class="col-lg-10">
<input class="form-control" placeholder="SSN" autocomplete="off" type="text" name="ssn" id="ssn" size="10" maxlength="20" value="<?php if (isset($_POST['ssn'])) echo $_POST['ssn']; ?>" />
</div>
</div>
<!-- submit button -->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-primary">Register</button>
</div>
</div>
</fieldset>
</form>
<?php include ('includes/footer.html'); ?>

84
grade.php Normal file
View File

@ -0,0 +1,84 @@
<?php # Script 9.5 - register.php #2
// This script performs an INSERT query to add a record to the users table.
$page_title = 'Course Grade';
include ('includes/header.html');
// Check for form submission:
// echo $_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between post and get?
require ('./mysqli_connect.php'); // Connect to the db.
$errors = array(); // Initialize an error array.
// Check for an email address:
if (empty($_POST['last_name'])) { //$_POST is a global variable. empty() method determines whether a variable is considered to be empty.
$errors[] = 'You forgot to enter the last name';
} else {
$ln = mysqli_real_escape_string($dbc, trim($_POST['last_name'])); //mysqli_real_escape_strin()escapes special characters in a string for use in an SQL statement.
}
if (empty($errors)) { // If there is no errors. If everything's OK.
// Make the query:
$q = "SELECT CONCAT (StuLastName, ', ', StuFirstName) AS name, CouLongName AS course,CourseGrades AS grade FROM Students, Courses, StudentClass, ScheduleOfClasses
WHERE Students.StudentID=StudentClass.StudentID AND
Courses.CourseID=ScheduleOfClasses.CourseID AND
ScheduleOfClasses.ScheduleID=StudentClass.ScheduleID AND
StuLastName='$ln'";
$r = @mysqli_query ($dbc, $q); // Run the query.
$num = mysqli_num_rows($r); //return the number of rows selected
if ($num > 0) { // If it ran OK, display the records.
// Print how many users there are:
echo "<p>There is the information for the student you are looking for.</p>\n";
// Table header.
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr><td align="left"><b>Student</b></td><td align="left"><b>Course</b></td><td align="left"><b>Grade</b></td></tr>
';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //MYSQLI_ASSOC makes the returned array assortative.
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['course'] . '</td><td align="left">' . $row['grade'] . '</td></tr>
';
}
echo '</table>'; // Close the table.
}
else { // If it did not run OK.
// Public message:
echo '<h1>Error</h1>
<p class="error">There is no student match with the information you provided</p>';
}
}
mysqli_close($dbc); // Close the database connection.
} // End of the main Submit conditional.
?>
<form class="form-horizontal" action="grade.php" method="post">
<fieldset>
<legend>Search Course Grade by Student Last Name</legend>
<div class="form-group">
<label for="last_name" class="col-lg-2 control-label">Student Last Name</label>
<div class="col-lg-10">
<input class="form-control" placeholder="Last Name" autocomplete="off" type="text" name="last_name" id="last_name" size="15" maxlength="20" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />
</div>
</div>
<!-- submit button -->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-primary">Search Course Grade</button>
</div>
</div>
</fieldset>
</form>
<?php include ('includes/footer.html'); ?>

11
includes/footer.html Normal file
View File

@ -0,0 +1,11 @@
<!-- Script 3.3 - footer.html -->
<div id="footer">
<hr/>
<p>Adapted from code by <a href="https://www.slis.uiowa.edu/research-profiles/ni-chaoqun-0">Chaoqun Ni</a>. Modified by <a href="http://www.simmons.edu/Faculty/Vicky-Steeves">Vicky Steeves</a> for Spring 2018 LIS-458-OL at Simmons SLIS. CSS and JS from <a href="https://getbootstrap.com" rel="nofollow">Bootstrap</a>. Theme is <a href="https://bootswatch.com/3/readable/">Readable</a> from <a href="https://bootswatch.com/">Bootswatch</a>.</p>
</div>
</div>
<!-- End of the page-specific content. -->
</body>
</html>

54
includes/header.html Normal file
View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo htmlspecialchars($page_title);?></title>
<!--Styling from Bootstrap v3.3.6-->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!--a specific style template for the website, currently using READABLE. you can find other themes here: https://bootswatch.com/3 and find the link to include in this file here: https://www.bootstrapcdn.com/legacy/bootswatch/-->
<link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/readable/bootstrap.min.css" rel="stylesheet" integrity="sha384-Li5uVfY2bSkD3WQyiHX8tJd0aMF91rMrQP5aAewFkHkVSTT2TmD2PehZeMmm7aiL" crossorigin="anonymous">
<!-- custom code to center the navigation. if you don't want centered navigation, get rid of this -->
<style>
.navbar-nav {
width: 100%;
text-align: center;
}
.navbar-nav > li {
float: none;
display: inline-block;
}
</style>
<!--JavaScript from Bootstrap v3.3.6-->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="row" style="text-align:center;">
<h1>Heading of Your Website</h1>
<h2>catchy slogan...</h2>
</div>
<div class="container">
<nav class="navbar navbar-default">
<div class="container">
<ul class="nav navbar-nav">
<!-- hyperlinks to pages within the site -->
<li><a href="index.php">Home Page</a></li>
<li><a href="ClassRoster.php">Class Roster</a></li>
<li><a href="employee.php">New Employee Register</a></li>
<li><a href="grade.php">Course Grade</a></li>
<li><a href="search.php">Search People</a></li>
</ul>
</div>
</nav>
<!-- Script 9.1 - header.html -->

20
index.php Normal file
View File

@ -0,0 +1,20 @@
<?php
$page_title = 'Welcome to this Site!';
include ('./includes/header.html');
?>
<h1>Big Header</h1>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<h2>Subheader</h2>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<p>This is where you'll put the main page content. This content will differ for each page.</p>
<?php
include ('./includes/footer.html');
?>

20
mysqli_connect.php Normal file
View File

@ -0,0 +1,20 @@
<?php # Script 9.2 - mysqli_connect.php
// This file contains the database access information.
// This file also establishes a connection to MySQL,
// selects the database to use, and sets the encoding.
// This file will be required in many other php files that need db connection.
// Set the database access information as constants:
DEFINE ('DB_USER', 'yourusername'); // you should put your username here
DEFINE ('DB_PASSWORD', 'studentid'); // you should put your password (studentID) here
DEFINE ('DB_HOST', 'dany.simmons.edu');
DEFINE ('DB_NAME', 'databasename'); // you should put the database name here.
// Make the connection.@ will make sure the error won't be returned if there is one.
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
// Set the encoding...
mysqli_set_charset($dbc, 'utf8');
?>

150
search.php Normal file
View File

@ -0,0 +1,150 @@
<?php # Script 9.5 - register.php #2
// This script performs an INSERT query to add a record to the users table.
$page_title = 'Search';
include ('includes/header.html');
// Check for form submission:
// echo $_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between post and get?
require ('./mysqli_connect.php'); // Connect to the db.
$errors = array(); // Initialize an error array.
// Check for an email address:
if (empty($_POST['first_name'])) { //$_POST is a global variable. empty() method determines whether a variable is considered to be empty.
$errors[] = 'You forgot to enter the first name';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['first_name'])); //mysqli_real_escape_strin()escapes special characters in a string for use in an SQL statement.
}
if (empty($errors)) { // If there is no errors. If everything's OK.
// Make the query:
$q = "SELECT CONCAT(StuLastName, ', ', StuFirstName) AS name, StuEmail, Mobile FROM Students where StuFirstName='$fn'";
$r = @mysqli_query ($dbc, $q); // Run the query.
$num = mysqli_num_rows($r);
if ($num > 0) { // If it ran OK, display the records.
// Print how many users there are:
echo "<p>There is the information for the student you are looking for.</p>\n";
// Table header.
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr><td align="left"><b>Name</b></td><td align="left"><b>Email</b></td><td align="left"><b>Mobile</b></td></tr>
';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //MYSQLI_ASSOC makes the returned array assortative.
echo '<tr><td align="left">' . $row['name'] . '</td><td align="left">' . $row['StuEmail'] . '</td><td align="left">' . $row['Mobile'] . '</td></tr>
';
}
echo '</table>'; // Close the table.
}
else { // If it did not run OK.
// Public message:
echo '<h1>Error</h1>
<p class="error">There is no student match with the information you provided</p>';
}
}
mysqli_close($dbc); // Close the database connection.
} // End of the main Submit conditional.
?>
<form class="form-horizontal" action="search.php" method="post">
<fieldset>
<legend>Search Students by First Name</legend>
<div class="form-group">
<label for="first_name" class="col-lg-2 control-label">First Name</label>
<div class="col-lg-10">
<input class="form-control" placeholder="First Name" autocomplete="off" type="text" name="first_name" id="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" />
</div>
</div>
<!-- submit button -->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-primary">Search Students</button>
</div>
</div>
</fieldset>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between post and get?
require ('./mysqli_connect.php'); // Connect to the db.
$errors = array(); // Initialize an error array.
// Check for an email address:
if (empty($_POST['last_name'])) { //$_POST is a global variable. empty() method determines whether a variable is considered to be empty.
$errors[] = 'You forgot to enter the last name';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['last_name'])); //mysqli_real_escape_strin()escapes special characters in a string for use in an SQL statement.
}
if (empty($errors)) { // If there is no errors. If everything's OK.
// Make the query:
$q = "SELECT CONCAT(LecLastName, ', ', LecFirstName) AS lecname, LecEmail, WTel FROM Lecturers where LecLastName='$fn'";
$r = @mysqli_query ($dbc, $q); // Run the query.
$num = mysqli_num_rows($r);
if ($num > 0) { // If it ran OK, display the records.
// Print how many lecturers there are:
echo "<p>There is the information for the lecturer you are looking for.</p>\n";
// Table header.
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr><td align="left"><b>Name</b></td><td align="left"><b>Email</b></td><td align="left"><b>Telphone</b></td></tr>
';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //MYSQLI_ASSOC makes the returned array assortative.
echo '<tr><td align="left">' . $row['lecname'] . '</td><td align="left">' . $row['LecEmail'] . '</td><td align="left">' . $row['WTel'] . '</td></tr>
';
}
echo '</table>'; // Close the table.
}
else { // If it did not run OK.
// Public message:
echo '<h1>Error</h1>
<p class="error">There is no lecturer match with the information you provided</p>';
}
}
mysqli_close($dbc); // Close the database connection.
} // End of the main Submit conditional.
?>
<form class="form-horizontal" action="search.php" method="post">
<fieldset>
<legend>Search Lecturers by Last Name</legend>
<div class="form-group">
<label for="last_name" class="col-lg-2 control-label">Last Name</label>
<div class="col-lg-10">
<input class="form-control" placeholder="Last Name" autocomplete="off" type="text" name="last_name" id="last_name" size="15" maxlength="20" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />
</div>
</div>
<!-- submit button -->
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" name="submit" class="btn btn-primary">Search Lecturers</button>
</div>
</div>
</fieldset>
</form>
<?php include ('includes/footer.html'); ?>

70
show_roster.php Normal file
View File

@ -0,0 +1,70 @@
<?php # Script 9.5 - ClassRoster.php #2
// This script performs an INSERT query to add a record to the users table.
$page_title = 'Class Roster';
include ('includes/header.html');
// Check for form submission:
// echo $_SERVER['REQUEST_METHOD'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between post and get?
require ('./mysqli_connect.php'); // Connect to the db.
$errors = array(); // Initialize an error array.
// Check for an courese information:
if (empty($_POST['course_name'])) { //$_POST is a global variable. empty() method determines whether a variable is considered to be empty.
$errors[] = 'You forgot to enter the course name';
} else {
$fn = mysqli_real_escape_string($dbc, trim($_POST['course_name'])); //mysqli_real_escape_strin()escapes special characters in a string for use in an SQL statement.
}
if (empty($errors)) { // If there is no errors. If everything's OK.
// Make the query:
$q = "SELECT CouLongName, CONCAT(SemesterName, Semesters.SemesterYear) as SemesterInf, CONCAT(StuLastName, ', ', StuFirstName) as name from Students, Semesters, Courses, StudentClass, ScheduleOfClasses
WHERE Students.StudentID=StudentClass.StudentID AND
ScheduleOfClasses.CourseID=Courses.CourseID AND
ScheduleOfClasses.ScheduleID=StudentClass.ScheduleID AND
ScheduleOfClasses.SemesterID=Semesters.SemesterID AND
CouLongName='$fn'";
$r = @mysqli_query ($dbc, $q); // Run the query.
$num = mysqli_num_rows($r);
if ($num > 0) { // If it ran OK, display the records.
// Print how many users there are:
echo "<p>There is the information for the course you are looking for.</p>\n";
// Table header.
echo '<table align="center" cellspacing="3" cellpadding="3" width="75%">
<tr><td align="left"><b>Course Name</b></td><td align="left"><b>Semester</b></td><td align="left"><b>Student Name</b></td></tr>';
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { //MYSQLI_ASSOC makes the returned array assortative.
echo '<tr><td align="left">' . $row['CouLongName'] . '</td><td align="left">' . $row['SemesterInf'] . '</td><td align="left">' . $row['name'] . '</td></tr>
';
}
echo '</table>'; // Close the table.
}
else { // If it did not run OK.
// Public message:
echo '<h1>Error</h1>
<p class="error">There is no course roster match with the information you provided</p>';
}
}
mysqli_close($dbc); // Close the database connection.
} // End of the main Submit conditional.
?>
<h1>Class Roster</h1>
<form action="ClassRoster.php" method="post">
<p>Course Name <input type="text" name="course_name" size="15" maxlength="50" value="<?php if (isset($_POST['course_name'])) echo $_POST['course_name']; ?>" /></p>
<p><input type="submit" name="submit" value="Show Class Roster" /></p>
</form>
<?php include ('includes/footer.html'); ?>