I am creating a log in system using a mysql database.
I have two tables in the database called student and discipline. I want users to log in using two different things from different tables. I want them to log in using their student ID, which is in the student table, and their discipline name, which is in the discipline table. student and discipline are both separate tables. I have created an inner join with the tables, and the query works in phpmyadmin. However, I cannot log in when i run the application. When i press the log in button, nothing seems to happen....
Below is my code:
// LOGIN USER
if (isset($_POST['login'])) {
$name = mysqli_real_escape_string($db, $_POST['name']);
$studentid = mysqli_real_escape_string($db, $_POST['studentid']);
}
if (count($errors) == 0) {
$name = md5($name);
$query = "SELECT discipline.name, student.studentid
FROM discipline
INNER JOIN student ON discipline.disciplineid = student.disciplineid WHERE discipline.name='$name' AND student.studentid='$studentid'";
//$query = "SELECT * FROM discipline WHERE name='$name' AND studentid='$studentid'";
$result = mysqli_query($db, $query);
}
if (mysqli_num_rows($result) == 1) {
$_SESSION['name'] = $name;
header('location: Assessment.php');
}else {
array_push($errors, "Wrong username/password combination");
}
//logout
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['disciplineid']);
header('location: index.php');
}
?>
Form HTML:
<div class="form">
<ul class="row justify-content-center">
<form method="post" action="index.php">
<p> <label>Your ID </label> <input type="text" id="studentid" name="studentid" required /> </p>
<p> <label>name of discipline:</label> <input type="text" id="name" name="name"required /> </p>
<p> <button type="submit" class="btn" name="login">Login</button> </p>
</form>
Any help would be appreciated. Thanks
– nad Jan 09 '18 at 16:04