erreur de l'exécution du programme
Posté : 22 mars 2013, 04:47
Bonjour à tous,
J'ai des erreurs sur le programme que je n'arrive pas à résoudre. Voici le premier fichier qui récupère des requêtes :
<!DOCTYPE HTML>
<html>
<head>
<title>Recherche dans le catalogue </title>
</head>
<body>
<form action="resultats.php" method="post">
Choisissez un type de recherche;:<br />
<select name="type_recherche">
<option value="auteur">Par auteur</option>
<option value="titre">Par titre</option>
<option value="isbn">Par ISBN</option>
</select>
<br />
Entrez le terme recherché: <br />
<input name="terme_recherche" type="text" size="40"/>
<br />
<input type="submit" value="Rechercher"/>
</form>
</body>
</html>
=======================================================================================================
Voici le fichier qui pose problème: resultat.php
<?php
// Création de variables aux noms abrégés
$type_recherche = $_POST['type_recherche'];
$terme_recherche = trim($_POST['terme_recherche']);
if (!$type_recherche || !$terme_recherche){
echo "Vous n'avez pas saisi les détails de la recherche";
exit();
}
if (!get_magic_quotes_gpc()){
$type_recherche = addslashes($type_recherche);
$terme_recherche = addslashes($terme_recherche);
}
@$db = new mysqli('localhost', 'root', '', 'livres');
if (mysqli_connect_errno()){
echo "Impossible de se connecter à la base de données.";
exit();
}
$requete = "select * from livres where ". $type_recherche .
"like '%$terme_recherche%'";
$resultat = $db->query($requete);
$nb_lig_resultat = $resultat->num_rows;
echo '<p>Nombre de livres trouvés: ' . $nb_lig_resultat . '<br/>';
for($i = 0; $i < $nb_lig_resultat; $i++){
$ligne = $resultat -> fetch_assoc();
echo "<p><strong>" .($i+1) . ". Titre : ";
echo htmlspecialchars(stripslashes($ligne['titre']));
echo "</strong><br/>Auteur : ";
echo "<br/>ISBN : ";
echo stripslashes($ligne['isbn']);
echo "<br/>Prix : ";
echo stripslashes($ligne['prix']);
echo '</p>';
}
$resultat->free();
$db->close();
?>
=======================================================================================
Quand je lance le programme j'ai l'erreur suivante:
( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Trying to get property of non-object in C:\wamp\www\Test\Chapitre-11\resultats.php on line 44
Call Stack
# Time Memory Function Location
1 0.0006 262528 {main}( ) ..\resultats.php:0
Nombre de livres trouvés:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to a member function free() on a non-object in C:\wamp\www\Test\Chapitre-11\resultats.php on line 60
Call Stack
# Time Memory Function Location
1 0.0006 262528 {main}( ) ..\resultats.php:0
=========================================================================
Merci de votre aide
J'ai des erreurs sur le programme que je n'arrive pas à résoudre. Voici le premier fichier qui récupère des requêtes :
<!DOCTYPE HTML>
<html>
<head>
<title>Recherche dans le catalogue </title>
</head>
<body>
<form action="resultats.php" method="post">
Choisissez un type de recherche;:<br />
<select name="type_recherche">
<option value="auteur">Par auteur</option>
<option value="titre">Par titre</option>
<option value="isbn">Par ISBN</option>
</select>
<br />
Entrez le terme recherché: <br />
<input name="terme_recherche" type="text" size="40"/>
<br />
<input type="submit" value="Rechercher"/>
</form>
</body>
</html>
=======================================================================================================
Voici le fichier qui pose problème: resultat.php
<?php
// Création de variables aux noms abrégés
$type_recherche = $_POST['type_recherche'];
$terme_recherche = trim($_POST['terme_recherche']);
if (!$type_recherche || !$terme_recherche){
echo "Vous n'avez pas saisi les détails de la recherche";
exit();
}
if (!get_magic_quotes_gpc()){
$type_recherche = addslashes($type_recherche);
$terme_recherche = addslashes($terme_recherche);
}
@$db = new mysqli('localhost', 'root', '', 'livres');
if (mysqli_connect_errno()){
echo "Impossible de se connecter à la base de données.";
exit();
}
$requete = "select * from livres where ". $type_recherche .
"like '%$terme_recherche%'";
$resultat = $db->query($requete);
$nb_lig_resultat = $resultat->num_rows;
echo '<p>Nombre de livres trouvés: ' . $nb_lig_resultat . '<br/>';
for($i = 0; $i < $nb_lig_resultat; $i++){
$ligne = $resultat -> fetch_assoc();
echo "<p><strong>" .($i+1) . ". Titre : ";
echo htmlspecialchars(stripslashes($ligne['titre']));
echo "</strong><br/>Auteur : ";
echo "<br/>ISBN : ";
echo stripslashes($ligne['isbn']);
echo "<br/>Prix : ";
echo stripslashes($ligne['prix']);
echo '</p>';
}
$resultat->free();
$db->close();
?>
=======================================================================================
Quand je lance le programme j'ai l'erreur suivante:
( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Trying to get property of non-object in C:\wamp\www\Test\Chapitre-11\resultats.php on line 44
Call Stack
# Time Memory Function Location
1 0.0006 262528 {main}( ) ..\resultats.php:0
Nombre de livres trouvés:
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to a member function free() on a non-object in C:\wamp\www\Test\Chapitre-11\resultats.php on line 60
Call Stack
# Time Memory Function Location
1 0.0006 262528 {main}( ) ..\resultats.php:0
=========================================================================
Merci de votre aide