gpt4 book ai didi

php - 程序返回: Fatal error: Call to a member function fetch() on a non-object

转载 作者:行者123 更新时间:2023-11-29 21:08:54 25 4
gpt4 key购买 nike

我查看了之前提出的所有类似问题,它们都有不同的代码,所以找不到答案!

我的问题是我的程序返回

Fatal error: Call to a member function fetch() on a non-object

当我的php代码从mysql数据库请求信息时运行。这是我的代码:

<body>
<?php
// Connexion à la base de données
include_once("connexionMysql.php");

// test si bouton ok
if (isset($_POST['valid'])) {
// construction de la req.
$requete="SELECT mdp, type FROM AY_users
WHERE login='.$_POST['login'].'";
// exécution de la requête
$reponse = $bdd->query($requete);

if ($donnees=$reponse->fetch(PDO::FETCH_ASSOC)) {
if ($donnees['mdp']==$_POST['mdp']) {
// le mot de passe est le bon

print "<br/>Authentification réussie ! <br/>\n";
if($donnees['type']==0){
header("Location: pageDaccueilAdmin.php");
}
if($donnees['type']==1){
header("Location: pageDaccueilEnseignant.php");
}
if($donnees['type']==2){
header("Location: pageDaccueilCher.php");
}
} else {
print "Le mot de passe n'est pas le bon, veuillez reessayer<br/>";
print "<a href='authentif.php'>Se reconnecter</a>";
}
} else {
// sinon : login inexistant
print "Ce login est inexistant, veuillez <br/>\n";
print "1- <a href='authentif.php'>Se reconnecter</a>";
print "2- <a href='creer.php'>créer un compte</a>";
}

}

?>

它肯定连接到数据库,因为我有一个打印语句来确认。 (mdp-->密码)*

最佳答案

由于引号格式错误,您的查询无法从数据库获取任何实例

试试这个方法

$requete="SELECT mdp, type FROM AY_users 
WHERE login='" .$_POST['login']. "'";
// exécution de la requête
$reponse = $bdd->query($requete);

关于php - 程序返回: Fatal error: Call to a member function fetch() on a non-object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36581068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com