我用下面的代码让fetchAll发生了一个非对象错误:
var_dump($_POST);
include('config_path.php');
$bdd->query("SET NAMES 'utf8'");
$req = $bdd->prepare("SELECT * FROM admin WHERE nom_uti_admin= :username AND mdp_admin=:password");
$result = $req->execute(array(
'username' => $_POST['username'],
'password' => $_POST['password']
));
$connect = $result->fetchAll();var_dump返回最后一页表单的右值...你知道错误是什么吗?该请求在phpmyadmin中的真值下工作得很好!
谢谢
编辑:
以下代码验证:
if(isset($_POST['username']) && isset($_POST['password'])){
if(count($connect) == 1){
$_SESSION['auth'] = $cle;
$_SESSION['username'] = $_POST['username'];
header("Location: admin/afficher_spec.php");
}else if(count($connect) == 0){
echo 'nom d\'utilisateur et/ou mot de passe incorrect !';
}
}else {
echo 'Veuillez remplir tous les champs ';
}发布于 2016-01-11 22:33:41
只有当您想要使用fetchAll循环遍历它时,才使用foreach。在本例中,您只需要返回一条记录,因此需要使用fetch
$connect = $result->fetch(PDO::FETCH_ASSOC);
if(count($connect) == 1){$_SESSION['auth'] = $cle;
$_SESSION['username'] = $_POST['username'];
header("Location: admin/afficher_spec.php");
}else if(count($connect) != 1){
echo 'nom d\'utilisateur et/ou mot de passe incorrect !';
}https://stackoverflow.com/questions/34721456
复制相似问题