I looked through all the previously asked similar questions and they all have different code so can't find an answer!
My problem is that my program returns
Fatal error: Call to a member function fetch() on a non-object
when my php code is run when requesting information from mysql database. Here is my code:
<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>";
}
}
?>
It definitely connects to the database as I have a print statement to make sure. (mdp-->password)*