query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
$stmt = $DB->prepare($sql);
$stmt->execute();
$rowCount = $stmt->rowCount();
if($rowCount > 0){
while ($row = $q->fetch()){
$_SESSION["userloggedin"] = 'true';
$_SESSION["user_name"] = $row['name'];
$_SESSION["user_email"] = $row['email'];
header("Location: profile.html");
exit();
}
} else {
$msg .= '
User name or Password invalid.
';
}
}
$erorrMsg = '';
if(isset($_POST['reset-pw'])){
$email = $_POST['email'];
$sql = "SELECT * FROM module_students WHERE email LIKE '%".$email."%' AND status LIKE 'active'";
$stmt = $DB->prepare($sql);
$stmt->execute();
$rowCount = $stmt->rowCount();
if($rowCount > 0){
$token = openssl_random_pseudo_bytes(16);
//Convert the binary data into hexadecimal representation.
$token = bin2hex($token);
try {
$sql = "UPDATE module_students SET token='".$token."' WHERE email='".$email."' AND status='active'";
$sth = $DB->query($sql);
} catch(PDOException $e) {
echo $e->getMessage();
}
include('inc/reset-pw-email.php');
$erorrMsg .= 'A password reset link was sent to your email address
';
} else {
$erorrMsg .= 'Email does not exist!
';
}
}
?>