【发布时间】:2020-06-08 19:57:54
【问题描述】:
我想在登录后将teacher_id 作为会话变量传递。在 loginteacher.php 中,我已将用户电子邮件作为会话变量传递。
loginteacher.php
<?php
session_start();
//Database Configuration File
include('database.php');
error_reporting(1);
if (isset($_POST['submit'])) {
// Getting username/ email and password
$email=$_POST['email'];
$password=$_POST['password'];
$teacher_id = $_POST['teacher_id'];
// Fetch data from database on the basis of username/email and password
$sql ="SELECT teacher_id, email ,password FROM teacher WHERE (email=:email and teacher_id=:teacher_id)";
$query= $conn -> prepare($sql);
$query-> bindParam(':email', $email,':teacher_id', $teacher_id, PDO::PARAM_STR);
$query-> execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
if ($query->rowCount() > 0) {
foreach ($results as $row) {
$passwordhash = $row->password;
}
//verifying Password
$pass =password_verify($password,$passwordhash);
if ($pass)
{
$_SESSION['email']=$_POST['email'];
$_SESSION['teacher_id']=$_POST['teacher_id'];
header('location:http://localhost/kridha/teacherdashboard.php');
}
else
{
echo "<script type='text/javascript'>alert('wrong credtials');
window.location='teacher.html';
</script>";
}
}
//if username or email not found in database
else{
echo "<script type='text/javascript'>alert('User not registered with us');
window.location='teacher.html';
</script>";
}
}
?>
这里我已经回显了会话 ID。
teacherdashboard.php
<?php
session_start();
if(!isset($_SESSION['email']))
{
// not logged in
header('Location: teacher.html');
exit();
}
echo $_SESSION['teacher_id'];
?>
但它显示了这个错误
致命错误:未捕获的 PDOException:SQLSTATE[42000]:语法错误或 访问冲突:1064 您的 SQL 语法有错误;检查 与您的 MariaDB 服务器版本相对应的手册 在第 1 行的 ':email 和 teacher_id=:teacher_id' 附近使用的语法 C:\xampp\htdocs\kridha\loginteacher.php:22
堆栈跟踪:
#0 C:\xampp\htdocs\kridha\loginteacher.php(22): PDOStatement->execute()
#1 {main}
在第 22 行的 C:\xampp\htdocs\kridha\loginteacher.php 中抛出
【问题讨论】:
-
问题与会话变量无关,是MySQL的问题。
-
@Barmar They asked this already。在另一个帐户下。我认为你在浪费时间。