Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions README.md

This file was deleted.

2 changes: 1 addition & 1 deletion _includes/dbconnect.inc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
// replace mysqllogin and mysqlpassword with your own
$conn = mysqli_connect("localhost", "root", "", "oss-cw2");
$conn = mysqli_connect("localhost", "PHPproject", "gRjNO4PIXCGInKIk", "cw2_students");

if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
Expand Down
120 changes: 60 additions & 60 deletions _includes/functions.inc
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
<?php
include "passwordLib.php";
/**
* Validate Login function
*
* @param $id - user ID
* @param $password - plaintext password
* @return boolean - returns true or false depending on successful authentication of user.
*/
function validatelogin($id,$password) {
global $conn;
// Build an SQL statment that will return a record with a matching id
$sql = "select * from student where studentid='$id';";
//echo $sql;
$loginresult = mysqli_query($conn, $sql);
$studentdetails = mysqli_fetch_assoc($loginresult);
//print_r($studentdetails);
// use PHP's verify_password function to check whether the stored
// hash matches the given password
if (password_verify($password, $studentdetails['password'])) {
$_SESSION['id'] = $id;
return true;
}
else {
$_SESSION['id'] = '';
return false;
}
}
/**
* Simple Templating function
*
* @param $file - Path to the PHP file that acts as a template.
* @param $args - (optional) Associative array of variables to pass to the template file.
* @return string - Output of the template file. Likely HTML.
*
* Source: http://www.daggerhart.com/create-simple-php-templating-function/
*/
function template( $file, $args=array() ){
// ensure the file exists
if ( !file_exists( $file ) ) {
return '';
}
// Make values in the associative array easier to access by extracting them
if ( is_array( $args ) ){
extract( $args );
}
// buffer the output (including the file is "output")
ob_start();
include $file;
return ob_get_clean();
}
?>
<?php

include "passwordLib.php";

/**
* Validate Login function
*
* @param $id - user ID
* @param $password - plaintext password
* @return boolean - returns true or false depending on successful authentication of user.
*/
function validatelogin($id,$password) {
global $conn;
// Build an SQL statment that will return a record with a matching id
$sql = "select * from student where studentid='$id';";
//echo $sql;
$loginresult = mysqli_query($conn, $sql);
$studentdetails = mysqli_fetch_assoc($loginresult);
//print_r($studentdetails);

// use PHP's verify_password function to check whether the stored
// hash matches the given password
if (password_verify($password, $studentdetails['password'])) {
$_SESSION['id'] = $id;
return true;
}
else {
$_SESSION['id'] = '';
return false;
}
}


/**
* Simple Templating function
*
* @param $file - Path to the PHP file that acts as a template.
* @param $args - (optional) Associative array of variables to pass to the template file.
* @return string - Output of the template file. Likely HTML.
*
* Source: http://www.daggerhart.com/create-simple-php-templating-function/
*/
function template( $file, $args=array() ){
// ensure the file exists
if ( !file_exists( $file ) ) {
return '';
}

// Make values in the associative array easier to access by extracting them
if ( is_array( $args ) ){
extract( $args );
}

// buffer the output (including the file is "output")
ob_start();
include $file;
return ob_get_clean();
}

?>
90 changes: 45 additions & 45 deletions _sql/college.dump
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
CREATE TABLE `module` (
`modulecode` varchar(10) NOT NULL,
`name` varchar(100) NOT NULL,
`level` int(11) NOT NULL
);
CREATE TABLE `student` (
`studentid` varchar(8) NOT NULL,
`password` varchar(100) NOT NULL,
`dob` date NOT NULL,
`firstname` varchar(20) NOT NULL,
`lastname` varchar(20) NOT NULL,
`house` varchar(30) NOT NULL,
`town` varchar(30) NOT NULL,
`county` varchar(30) NOT NULL,
`country` varchar(30) NOT NULL,
`postcode` varchar(10) NOT NULL
);
CREATE TABLE `studentmodules` (
`studentid` varchar(8) NOT NULL,
`modulecode` varchar(10) NOT NULL
);
INSERT INTO `studentmodules` (`studentid`, `modulecode`) VALUES
('20000000', 'CO107'),
('20000000', 'IN251');
INSERT INTO `module` (`modulecode`, `name`, `level`) VALUES
('CO106', 'Programming Development', 1),
('CO107', 'Programming Principles', 1),
('IN251', 'Internet Systems Development', 2);
INSERT INTO `student` (`studentid`, `password`, `dob`, `firstname`, `lastname`, `house`, `town`, `county`, `country`, `postcode`) VALUES
('20000000', '$2y$10$.LJBOl64nZWEVVE/v5mgNuzR01zx1zoyXuGJUa/zp2U.MQxkps3LS', '1974-11-10', 'Jon', 'Smith', '23 Victoria Road', 'High Wycombe', 'Bucks', 'UK', 'HP11 1RT');
ALTER TABLE `module`
ADD PRIMARY KEY (`modulecode`);
ALTER TABLE `student`
ADD PRIMARY KEY (`studentid`);
ALTER TABLE `studentmodules`
ADD PRIMARY KEY (`studentid`,`modulecode`);
CREATE TABLE `module` (
`modulecode` varchar(10) NOT NULL,
`name` varchar(100) NOT NULL,
`level` int(11) NOT NULL
);

CREATE TABLE `student` (
`studentid` varchar(8) NOT NULL,
`password` varchar(100) NOT NULL,
`dob` date NOT NULL,
`firstname` varchar(20) NOT NULL,
`lastname` varchar(20) NOT NULL,
`house` varchar(30) NOT NULL,
`town` varchar(30) NOT NULL,
`county` varchar(30) NOT NULL,
`country` varchar(30) NOT NULL,
`postcode` varchar(10) NOT NULL
);

CREATE TABLE `studentmodules` (
`studentid` varchar(8) NOT NULL,
`modulecode` varchar(10) NOT NULL
);

INSERT INTO `studentmodules` (`studentid`, `modulecode`) VALUES
('20000000', 'CO107'),
('20000000', 'IN251');

INSERT INTO `module` (`modulecode`, `name`, `level`) VALUES
('CO106', 'Programming Development', 1),
('CO107', 'Programming Principles', 1),
('IN251', 'Internet Systems Development', 2);

INSERT INTO `student` (`studentid`, `password`, `dob`, `firstname`, `lastname`, `house`, `town`, `county`, `country`, `postcode`) VALUES
('20000000', '$2y$10$.LJBOl64nZWEVVE/v5mgNuzR01zx1zoyXuGJUa/zp2U.MQxkps3LS', '1974-11-10', 'Jon', 'Smith', '23 Victoria Road', 'High Wycombe', 'Bucks', 'UK', 'HP11 1RT');


ALTER TABLE `module`
ADD PRIMARY KEY (`modulecode`);

ALTER TABLE `student`
ADD PRIMARY KEY (`studentid`);

ALTER TABLE `studentmodules`
ADD PRIMARY KEY (`studentid`,`modulecode`);
74 changes: 74 additions & 0 deletions addstudent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php include("_includes/config.inc"); include("_includes/dbconnect.inc"); include("_includes/functions.inc"); echo template("templates/partials/header.php"); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add New Student</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
.btn-primary {
font-size: 1.2rem;
font-weight: bold;
padding: 0.8rem 1.5rem;
}
</style>
</head>
<body>
<?php echo template("templates/partials/nav.php"); ?>
<div class="container mt-5">
<h2 class="text-center mb-4">Add New Student</h2>
<div class="row justify-content-center">
<div class="col-md-8">
<form action="process_addstudent.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="studentid">Student ID:</label>
<input type="text" class="form-control" id="studentid" name="studentid" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="form-group">
<label for="dob">Date of Birth:</label>
<input type="date" class="form-control" id="dob" name="dob" required>
</div>
<div class="form-group">
<label for="firstname">First Name:</label>
<input type="text" class="form-control" id="firstname" name="firstname" required>
</div>
<div class="form-group">
<label for="lastname">Last Name:</label>
<input type="text" class="form-control" id="lastname" name="lastname" required>
</div>
<div class="form-group">
<label for="house">House:</label>
<input type="text" class="form-control" id="house" name="house">
</div>
<div class="form-group">
<label for="town">Town:</label>
<input type="text" class="form-control" id="town" name="town">
</div>
<div class="form-group">
<label for="county">County:</label>
<input type="text" class="form-control" id="county" name="county">
</div>
<div class="form-group">
<label for="country">Country:</label>
<input type="text" class="form-control" id="country" name="country">
</div>
<div class="form-group">
<label for="postcode">Postcode:</label>
<input type="text" class="form-control" id="postcode" name="postcode">
</div>
<div class="form-group">
<label for="image">Student Image:</label>
<input type="file" class="form-control-file" id="image" name="image">
</div>
<button type="submit" class="btn btn-primary btn-block btn-lg">Add Student</button>
</form>
</div>
</div>
</div>
</body>
</html>
Loading