connection files (dbConnection.php)
<?php
$_SESSION["conn"]=mysqli_connect("localhost","root","","club_managing_system","3306");
$con=mysqli_connect("localhost","root","","club_managing_system","3306");
//Check connection
if(mysqli_connect_errno())
{
echo "Failed to connect to database:".mysqli_connect_error();
}
?>
html files (forgotPass.php)
<?php
include '../api/crudHandler.php';
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>forgot password page</title>
<link rel="stylesheet" href="../css/loginPage.css">
</head>
<body>
<div class="center" style="top:50%">
<h1>Forgot Password</h1>
<form method="post" onsubmit="return checkPass()">
<div>
<a style="font-size:12px">Please insert your email to reset the password</a>
</div>
<div class="txt_field">
<input type="email" name="email" id="email">
<span></span>
<label>Email</label>
</div>
<div>
<a style="font-size:12px">Please enter your new password</a>
</div>
<div class="txt_field">
<input type="password" name="new_password" id="password">
<span></span>
<label>New Password</label>
</div>
<div>
<a style="font-size:12px">Please confirm your new password</a>
</div>
<div class="txt_field">
<input type="password" name="confirm_password" id="password2">
<span></span>
<label>Confirm Password</label>
</div>
<input type="submit" value="Submit" >
<div class="signup_link">
Still remember your password? <a href="loginPage.php">Log In</a>
<span id = "message" style="color:red"> </span>
</div>
</form>
</div>
</body>
<script type = "text/javascript">
function checkPass() {
var emailTF = document.getElementById('email').value;
var pass1 = document.getElementById('password').value;
var pass2 = document.getElementById('password2').value;
if (emailTF != ""){
if(pass1 != "" && pass2 != ""){
if(pass1 == pass2){
<?php
if (isset($_POST['email']) && isset($_POST['confirm_password'])) {
echo studentChangeCred($_POST['email'], $_POST['confirm_password']);
return;
}
?>
}else{
document.getElementById("message").innerHTML = "Password confirmation invalid!";
return false
}
}else{
document.getElementById("message").innerHTML = "Fill the password please!";
return false;
}
}else{
document.getElementById("message").innerHTML = "Fill your email please!";
return false
}
}
</script>
</html>
a file to call the functions out (crudHandler.php)
<?php
include_once("dbConnection.php");
function studentChangeCred($email,$pwd){
$studentDataSql = "SELECT * FROM 'student' WHERE 'student_email'= '" .$email. "'";
$result = ($_SESSION["conn"]->query($studentDataSql));
$_SESSION['validEmail'] = false;
if (!empty($result) && $result->num_rows > 0){
while($row = $result->fetch_assoc()){
if($row["student_email"] === $email){
$_SESSION['validEmail'] = true;
break;
}else{
$_SESSION['validEmail'] = false;
}
}
}else{
$_SESSION['validEmail'] = false;
}
$studentChangeCredSql = "UPDATE `student` SET `student_password` = '" .$pwd. "' WHERE 'student_email' = '" .$email. "'";
while($_SESSION['validEmail'] = true){
if($_SESSION["conn"]->query($studentChangeCredSql) === TRUE){
echo '<script type="text/javascript">
alert("Password changed successfully! Directing to login page!");
</script>';
echo "Error: " . $studentChangeCredSql . ":-" . mysqli_error($_SESSION['conn']);
header('Refresh:0.1,URL=loginPage.php');
break;
}else{
echo "Error: " . $studentChangeCredSql . ":-" . mysqli_error($_SESSION['conn']);
}
}
while($_SESSION['validEmail'] = false){
echo '<script type="text/javascript">
alert("This email is not registered, please try again!");
</script>';
break;
}
}
?>
Database table of student database
The method that I'm using is almost the same for another part of this project, not sure why but I think it's the mysqli's code problem, however, I can't seem to find the problem. I'm a beginner btw :)