added old scripts

This commit is contained in:
Vicky Steeves 2018-02-17 20:30:12 -05:00
parent 59e65e52e2
commit e3de1cb6f7
13 changed files with 553 additions and 248 deletions

View File

@ -19,22 +19,24 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
$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
$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' AND Semesters.SemesterName='$sn' AND Semesters.SemesterYear='$sy'";
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
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";
@ -63,74 +65,10 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
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>
<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'); ?>

View File

@ -19,21 +19,27 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
$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, Semesters.SemesterYear) as SemesterInf, CONCAT(StuLastName, ', ', StuFirstName) as name from Students, Semesters, Courses, StudentClass, ScheduleOfClasses
$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'";
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";
@ -62,8 +68,46 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
} // End of the main Submit conditional.
?>
<h1>Class Roster</h1>
<form action="ClassRoster.php" method="post">
<form action="ClassRoster_new.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>
<label>Semester Name</label>
<select name="semester_name">
<option value="semester" selected>--Semester--</option>
<option value="Fall">Fall</option>
<option value="Spring">Spring</option>
<option value="Summer">Summer</option>
</select><br/>
<label>Semester Year</label>
<select name="semester_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> <br/>
<p><input type="submit" name="submit" value="Show Class Roster" /></p>
</form>

View File

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

View File

@ -99,54 +99,15 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
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>
<h1>Register</h1>
<form action="employee.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
<p>Gender: <input type="text" name="gender" size="10" maxlength="20" value="<?php if (isset($_POST['gender'])) echo $_POST['gender']; ?>" /></p>
<p>SSN: <input type="text" name="ssn" size="10" maxlength="20" value="<?php if (isset($_POST['ssn'])) echo $_POST['ssn']; ?>" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
</form>
<?php include ('includes/footer.html'); ?>

View File

@ -62,23 +62,10 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
} // 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>
<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>
<?php include ('includes/footer.html'); ?>

View File

@ -1,11 +1,8 @@
<!-- Script 3.3 - footer.html -->
<!-- End of the page-specific content. --></div>
<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>
<p>Copyright &copy; <a href="#">Plain and Simple</a> 2016 | Designed by <a href="www.simmons.edu">Simmons College</a> | Sponsored by <a href="http://www.simmons.edu/">Chaoqun Ni</a> | Valid <a href="http://jigsaw.w3.org/css-validator/">CSS</a> &amp; <a href="http://validator.w3.org/">XHTML</a></p>
</div>
</div>
<!-- End of the page-specific content. -->
</body>
</html>

View File

@ -1,54 +1,24 @@
<!DOCTYPE html>
<!--document declaration. tells the browser which version of html this script uses-->
<!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><?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>
<title><?php echo $page_title; ?></title>
<link rel="stylesheet" href="includes/style.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<div class="row" style="text-align:center;">
<div id="header">
<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>
<div id="navigation">
<ul>
<li><a href="index.php">Home Page</a></li> <!-- hyperlinks to pages within the site -->
<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>
<div id="content"><!-- Start of the page-specific content. -->
<!-- Script 9.1 - header.html -->

117
includes/style.css Normal file
View File

@ -0,0 +1,117 @@
* {
border:0;
margin:0;
padding:0;
}
/* general */
a {
color:#777;
text-decoration:none;
}
a:hover {
color:#333;
text-decoration:none;
}
/* body */
body {
background:#ffffff;
color:#555;
font:0.8em Arial, Helvetica, "bitstream vera sans", sans-serif;
}
/* header */
#header {
border-bottom:1px solid #999;
height:80px;
margin:0 auto;
width:751px;
}
#header h1 {
color:#888;
font-size:300%;
letter-spacing:-3px;
text-align:right;
padding:5px;
margin-bottom:-20px;
}
#header h2 {
color:#CCC;
font-size:200%;
letter-spacing:-2px;
text-align:right;
}
/* navigation */
#navigation {
background:#fafafa;
border-right:1px solid #999;
margin:0 auto;
width:750px;
height:40px;
list-style:none;
}
#navigation li {
border-left:1px solid #999;
float:left;
width:149px;
list-style:none;
}
#navigation a {
color:#555;
display:block;
line-height:40px;
text-align:center;
}
#navigation a:hover {
background:#e3e3e3;
color:#555;
}
#navigation .active {
background:#e3e3e3;
color:#777;
}
/* content */
#content {
height:auto;
margin:0 auto;
padding:0 0 20px;
width:751px;
}
#content h1 {
border-bottom:1px dashed #999;
font-size:1.8em;
padding:20px 0 0;
}
#content p {
padding:20px 20px 0;
}
/* footer */
#footer {
border-top:1px solid #999;
height:50px;
margin:0 auto;
padding:10px;
text-align:center;
width:751px;
}
/* Added by Larry Ullman: */
.error, .ad {
font-weight: bold;
color: #C00
}
input, select, .input {
padding: 5px;
font-weight: bold;
font-size: 1em;
color: #008040;
background: #FFFFFF;
border:1px dotted #004080;
}

View File

@ -1,20 +1,17 @@
<?php
<?php # Script 3.4 - index.php
$page_title = 'Welcome to this Site!';
include ('./includes/header.html');
?>
<h1>Big Header</h1>
<h1 id="mainhead">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');
?>

38
instructions.txt Normal file
View File

@ -0,0 +1,38 @@
Modifying PHP code to communicate with your database
(1). Please download Lab10.zip from Moodle, and unzip the files onto your computer. You will see multiple HTML files, css files and php files in the folder.
(2). You will see the following pages:
a. mysqli_connect.php: makes connection to the database account. Pages that will communicate with your MySQL database will need to use this file in order to connect.
b. index.php: the main page of the website
c. grade.php: retrieve course grade information for a student.
d. employee.php: insert a new lecturer into the database.
e. search.php: search lecturers and students by names
f. ClassRoster.php: retrieve the class roster for a specific course
g. The includes folder:
i. header.html: the header (log, navigation bar, etc.) section of each page on this website
ii. footer.html: the footer section of each page on this website
iii. style.css: the overall style of the website.
Please note that there are detailed comments in each php page. Make sure you read them carefully and understand what each proportion of PHP does.
(3). Please open the mysqli_connect.php file using a text editor. If you are on Windows, you can use Komodo Edit, Notepad++, PHP Storm, Eclipse, etc. If you are on Mac, you can use TextWrangler, Komodo Edit, Eclipse, etc. In the editor window, please modify the code accordingly so that the connection will be made to your own database on simmons server.
(4). Please upload all the files (but this word document) to LIS458 folder that you created under public_html. Make sure the folder called “include” is also moved to LIS458.
(5). Open a browser and type the following information to the address bar:
web.simmons.edu/~your username/LIS458/index.php
You should see the following page in the browser. Click the navigation section and take a look at each page.
(6). Please do the following task on each page:
a) On ClassRoster Page, please search the class roster information for “Computer Networks”. What does it return? Take a screenshot of the result and paste it below.
b) On New Employee Register page, insert a new lecturer with last name=”Smith”, first name=”Cecilia”, email=cecilia@test.com, gender=”female” and ssn=”1243568790”. What is the message returned? Take a screenshot and paste it below.
c) On the Course Grade page, please search for course grade for a student with last name=”Mcneil”. Take a screenshot of the returned result and paste it below.
d) On the Search People page, please search for a student with first name=” Irene”. Take a screenshot for the result and paste it below. Then search for a lecturer with last name=”Lowe”. Paste the result below.
(7). Please modify the search people page, so that you can search by lecturer last name or lecturer email address. Make sure you upload the modified search.php code onto Simmons server to overwrite the original one. Then you can search from your browser to see if the change works.
(8). Please modify the Class Roster page so that it allows search by Course Name and Semester Information. Please provide a list of semesters for users to select from (recall drop-down menu from the first lab). Similarly, upload the modified page to Simmons server and revisit it from your browser.

110
register.php Normal file
View File

@ -0,0 +1,110 @@
<?php # Script 9.5 - register.php #2
// This script performs an INSERT query to add a record to the users table.
$page_title = 'Register';
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']));
}
// Check for a password and match against the confirmed password:
if (!empty($_POST['pass1'])) {
if ($_POST['pass1'] != $_POST['pass2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = mysqli_real_escape_string($dbc, trim($_POST['pass1']));
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) { // If everything's OK.
// Register the user in the database...
// Make the query:
$q = "INSERT INTO users (first_name, last_name, email, pass, registration_date) VALUES ('$fn', '$ln', '$e', SHA1('$p'), NOW() )";
$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 registered. In Chapter 12 you will actually be able to log in!</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.
?>
<h1>Register</h1>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="15" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></p>
<p>Email Address: <input type="text" name="email" size="20" maxlength="60" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /> </p>
<p>Password: <input type="password" name="pass1" size="10" maxlength="20" value="<?php if (isset($_POST['pass1'])) echo $_POST['pass1']; ?>" /></p>
<p>Confirm Password: <input type="password" name="pass2" size="10" maxlength="20" value="<?php if (isset($_POST['pass2'])) echo $_POST['pass2']; ?>" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
</form>
<?php include ('includes/footer.html'); ?>

View File

@ -57,24 +57,10 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
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>
<h1>Search Students by First Name</h1>
<form action="search.php" method="post">
<p>First Name <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p><input type="submit" name="submit" value="Search Students" /></p>
</form>
<?php
@ -128,23 +114,9 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { //remember the difference between po
} // 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>
<h1>Search Lecturers by Last Name</h1>
<form action="search.php" method="post">
<p>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 Lecturers" /></p>
</form>
<?php include ('includes/footer.html'); ?>

175
search_email.php Normal file
View File

@ -0,0 +1,175 @@
<?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.
?>
<h1>Search Students by First Name</h1>
<form action="search.php" method="post">
<p>First Name <input type="text" name="first_name" size="15" maxlength="20" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" /></p>
<p><input type="submit" name="submit" value="Search Students" /></p>
</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.
?>
<?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['email'])) { //$_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 {
$em = mysqli_real_escape_string($dbc, trim($_POST['email'])); //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 LecEmail='$em'";
$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.
?>
<h1>Search Lecturers by Last Name</h1>
<form action="search_email.php" method="post">
<p>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 Lecturers My Last Name" /></p>
<p>Lecture Email <input type="text" name="email" size="15" maxlength="20" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" /></p>
<p><input type="submit" name="submit" value="Search Lecturers by Email" /></p>
</form>
<?php include ('includes/footer.html'); ?>