我找不到任何解决方案,我无法登录。它显示{“成功”:0,“消息”:“登录失败”}失败。我能知道代码有什么问题吗?非常感谢您的帮助。
的login.php
<?php
require("config.php");
if(!empty($_POST)){
$query = "SELECT * FROM lecturer WHERE lecID = :lecID";
$query_params=array(':lecID'=> $_POST['lecID']);
try{
$stmt=$db->prepare($query);
$result=$stmt->execute($query_params);
}catch(PDOException $ex){
$response["success"]=0;
$response["message"]="Database Error1. Please try again";
die(json_encode($response));
}
$validate_info=false;
//fetching rows from query
$row = $stmt->fetch();
if ($row){
if($_POST['lecPass'] === $row['lecPass']){
$login_ok==true;
}
}
if($login_ok){
//userLogin
$response['success']=1;
$response['message']="Login Successful";
die(json_encode($response));
}else{
$response["success"]=0;
$response["message"]= "Login Failure";
die(json_encode($response));
}
}
}
答案 0 :(得分:0)
您需要使用=
Assignment operator
代替comparison operator
==
$login_ok==true;
更改为
$login_ok=true;
答案 1 :(得分:0)
尝试从PDO连接字符串
中删除花括号(“{”和“}”)$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
当php用变量替换双引号字符串中的变量名时,它不会影响花括号,所以你的连接字符串看起来像这样 -
"mysql:host={localhost};dbname={fypesyst_evaluation};charset=utf8"
完成花括号,使主机和数据库名称不正确