lis-458-ol-php/grade.php

72 lines
2.8 KiB
PHP
Raw Normal View History

2018-02-18 01:28:11 +00:00
<?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.
?>
2018-02-18 01:30:12 +00:00
<h1>Search Course Grade by Student Last Name</h1>
<form action="grade.php" method="post">
<p>Student Last Name <input type="text" name="last_name" size="15" maxlength="20" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p><input type="submit" name="submit" value="Search Course Grade" /></p>
</form>
2018-02-18 01:28:11 +00:00
<?php include ('includes/footer.html'); ?>