bonjour j'ai un problème avec mon code je reçois cette erreur et je ne comprend pas
la voici "Fatal error: Uncaught Error: Call to a member function fetch() on boolean in C:\xampp\htdocs\logicomp\connexion.php:22 Stack trace: #0 C:\xampp\htdocs\logicomp\verif.php(17): verification('', '') #1 {main} thrown in C:\xampp\htdocs\logicomp\connexion.php on line 22"
et voici mon code
<?php
function verification($nom,$pass){
//connexion sql
$dbhote = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbbase = 'appli';
$dsn = "mysql:dbname=$dbbase;host=$dbhote";
$dbh = new PDO($dsn, $dbuser, $dbpass);
// creation de la requette sql
$nom_sql = $dbh->quote($nom);
$pass_sql = $dbh->quote($pass);
$sql = "SELECT count(*)as nbres FROM user"."WHERE login=$nom_sql AND pass=$pass_sql";
//exécution de la requette
$result = $dbh->query($sql);
$row = $result->fetch();
$result = null;
if($row['nbres']==1){
return TRUE;
}else{
return FALSE;
}
}
?>
la voici "Fatal error: Uncaught Error: Call to a member function fetch() on boolean in C:\xampp\htdocs\logicomp\connexion.php:22 Stack trace: #0 C:\xampp\htdocs\logicomp\verif.php(17): verification('', '') #1 {main} thrown in C:\xampp\htdocs\logicomp\connexion.php on line 22"
et voici mon code
<?php
function verification($nom,$pass){
//connexion sql
$dbhote = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbbase = 'appli';
$dsn = "mysql:dbname=$dbbase;host=$dbhote";
$dbh = new PDO($dsn, $dbuser, $dbpass);
// creation de la requette sql
$nom_sql = $dbh->quote($nom);
$pass_sql = $dbh->quote($pass);
$sql = "SELECT count(*)as nbres FROM user"."WHERE login=$nom_sql AND pass=$pass_sql";
//exécution de la requette
$result = $dbh->query($sql);
$row = $result->fetch();
$result = null;
if($row['nbres']==1){
return TRUE;
}else{
return FALSE;
}
}
?>