Bonjour,
j'ai un problème dans mon code , j'essaye à inserer certaines informations dans ma base de données, ces infos sont saisies dans un formulaire .
Au premier lieu j'ai réussi à inserer 5 infos , mais quand j'ajoutais des colonnes à ma table une erreur s'affiche comme suit:
"Fatal error: Call to a member function fetchAll() on boolean in C:\wamp64\www\insereannonce.php on line 258"
voici le code :
$sql= "INSERT INTO personne(Nom,Email,Telephone,Ville,Quartier,categorie,marque,annee,kilometrage,carosserie,couleur,carburant,transmission,cylindre,P_piscale,
etat_douniaer,description,prix,type_post) VALUES('".($_POST['nom'])."','".($_POST['email'])."','".($_POST['telephone'])."','".($_POST['choix'])."','".($_POST['choix*'])."','".($_POST['choix1'])."','".($_POST['choix2'])."'
,'".($_POST['choix3'])."','".($_POST['choix**'])."','".($_POST['choix4'])."','".($_POST['choix41'])."','".($_POST['choix5'])."','".($_POST['choix51'])."'
,'".($_POST['choix6'])."','".($_POST['choix61'])."','".($_POST['choix7'])."','".($_POST['text2'])."','".($_POST['text'])."','".($_POST['p'])."')";
;
$res=$conn->query($sql);}

$sql= " SELECT Nom,Email,Telephone,Ville,Quartier , categorie,marque,annee,kilometrage,carosserie,couleur,carburant,transmission,cylindre,P_piscale,
etat_douniaer,description,prix,type_post FROM personne ";

$sth=$conn->query($sql);

$result= $sth->fetchAll(PDO::FETCH_ASSOC);// ligne de l'erreur

foreach($result as $row){

echo "<tr>";

echo "<td>".$row['Nom']."</td>";
echo "<td>".$row['Email']."</td>"; 
echo "<td>".$row['Telephone']."</td>";
echo "<td>".$row['Ville']."</td>";
echo "<td>".$row['Quartier']."</td>";
echo "<td>".$row['categorie']."</td>";
echo "<td>".$row['marque']."</td>";
echo "<td>".$row['annee']."</td>";
echo "<td>".$row['kilometrage']."</td>";
echo "<td>".$row['carosserie']."</td>";
echo "<td>".$row['couleur']."</td>";
echo "<td>".$row['carburant']."</td>";
echo "<td>".$row['transmission']."</td>";
echo "<td>".$row['cylindre']."</td>";
echo "<td>".$row['P_piscale']."</td>";
echo "<td>".$row['etat_douniaer']."</td>";
echo "<td>".$row['description']."</td>";
echo "<td>".$row['prix']."</td>";
echo "<td>".$row['type_post']."</td>";

echo "</tr>";

}
echo "<center><table border=4>";
echo "<tr> <th>Nom</th> <th>Email</th> <th>Telephone</th> <th>Ville</th> <th>Quartier</th> <th>categorie</th> <th>marque</th> <th>annee</th>
<th>Kilometrage</th> <th>Carosserie</th> <th>Couleur</th> <th>Carburant</th> <th>Transmission</th> <th>Cylindre</th> <th>P_piscale</th>
<th>Etat_douanier</th> <th>Description</th> <th>Prix</th> <th>Type_post</th> </tr>";

echo "</table></center>";
?>
Veuillez s'ils vous plaît m'aider , j'ai passé toute l'aprés midi en essayant de résoudre le problème mais en vain .
Merci d'avance

4 réponses


SLK
Réponse acceptée

Salut,

Ça pourrait être la faute de frappe à douanier.
la même erreur dans le INSERT, dans le SELECT, et dans le echo

Attention,
$_POST['choix'] est écrit 2 fois. (peut-être que c'est fait exprès)
et $_POST['choix*'] dérange un peu, on devrait éviter d'utiliser "l'étoile" ici.

Sanae
Auteur

Oui , c'était une faute de frappe , j'ai écris "carosserie" dans le code , et j'ai dans ma base de donnée "carrosserie"
Mercii pour l'aide

Salut,C'est tous simplement parce que la requete ne retourne rien.
l'objet pdo retourne false dans ce cas ;)

alors false->fetchall() , ça fonctionne pas ;)

@+
Pierre

@sanae,
OK super.

@Pierrot01,
La question était évidemment :
Pourquoi il y a "false" dans "$sth" (pourquoi la requête ne retourne rien)