1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| <?php
// recherche_simple.php
// header() pour l'encodage UTF-8 à rajouter normalement
// démarrage de la session à rajouter normalement
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=projet', 'root', '', $pdo_options);
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
if ((isset($_POST['titre'])) || (isset($_POST['artiste'])) || (isset($_POST['film'])))
{
if ((isset($_POST['titre']))
{
// Un titre
$titre = $_POST['recherche'];
print_r($_POST);
$req = $bdd->prepare('SELECT id_audio AS id_produit, titre, artiste AS nom, quantite FROM cd_audio WHERE titre = :titre');
$req->bindValue(':titre', $titre, PDO::PARAM_STR);
$req->execute();
$total_resultat = $req->rowCount();
$resultat = $req->fetchAll();
}
else if (isset($_POST['artiste']))
{
$artiste = $_POST['recherche'];
$req = $bdd->query('SELECT id_audio AS id_produit, titre, artiste AS nom, quantite FROM cd_audio WHERE artiste = :artiste');
$req->bindValue(':artiste', $artiste, PDO::PARAM_STR);
$req->execute();
$total_resultat = $req->rowCount();
$resultat = $req->fetchAll();
}
else if (isset($_POST['film']))
{
$artiste = $_POST['recherche'];
$req = $bdd->query('SELECT id_film AS id_produit, titre, realisateur AS nom, quantite FROM cd_film WHERE titre = :film');
$req->bindValue(':artiste', $artiste, PDO::PARAM_STR);
$req->execute();
$total_resultat = $req->rowCount();
$resultat = $req->fetchAll();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if (isset($resultat, $total_resultat) && (int)$total_resultat > 0) {
?>
<table>
<tr>
<th>TITRE</th>
<th>NOM</th>
<th>QUANTITE</th>
<th>AU PANIER</th>
</tr>
<?php
foreach($resultat as $produit) {
?>
<tr>
<td><?php echo $produit['titre']; ?></td>
<td><?php echo $produit['nom']; ?></td>
<td><?php echo $produit['quantite']; ?></td>
<td>
<form action="acheter.php" method="post">
<p>
<input type="submit" name="valider" value="Acheter" />
<input type="hidden" name="quantite" value="1" />
<input type="hidden" name="id_produit" value="<?php echo $produit['id_produit']; ?>" />
</p>
</form>
</td>
</tr>
<?php
}
?>
</table>
<?php
}
else {
echo '<p>aucun résultat ne correspond à votre recherche</p>';
}
?>
</body>
</html> |
Partager