Bonjour,
Je dois faire face à un petit problème, c'est pourquoi je fais appel à votre aide !
Je suis élève en première année d'info, et j'ai un projet qui consiste à réaliser le site web d'un agent automobile. Je dois afficher son parc d'occasions et lui permettre de l'administrer. L'affichage marchait parfaitement bien jusqu'à aujourd'hui ou je me suis lancé dans la suppression des enregistrements :s
j'ai une erreur d'identifié après ma dernière ligne! Donc je pense qu'il s'agit d'une erreur de syntaxe, mais j'ai relu mon code une dizaine de fois et je ne vois pas(on a toujours plus de mal à voir ses propres erreurs :p)! C'est pourquoi je vous demande de jeter un coup d'oeil si vous avez le temps :D
Merci
Pour info je vérifie que la personne soit l'admin (déjà connecté et la variable de session contient une valeur) soit un simple utilisateur. Je n'affiche le bouton supprimer que si c'est l'admin.
<?php
if(isset($_POST['supprimer'])){
//récupération des checkbox cochées dans un array $b
$b=$_POST['b'];
$i = 0;
while ( $i < count( $b)){
$sup= " DELETE FROM occasion WHERE id_occas='$b[$i]'";
$supp = $db->query($sup);
$i++;
}
}
?>
</div>
<div id="content_table">
<br />
<br />
<table>
<tr>
<th> </th>
<th class="headerpty">Marque</th>
<th class="headerpty">Modèle</th>
<th class="headerpty">Version</th>
<th class="headerpty">Année</th>
<th class="headerpty">Couleur</th>
<th class="headerpty">Kilométrage</th>
<th class="headerpty">Puissance</th>
<th class="headerpty">Energie</th>
<th class="headerpty">Prix</th>
</tr>
<?php
session_start();
// La fonction du gestionnaire d'erreurs
function mon_gestionnaire_erreur ($no_err, $mess_err, $fic_err,
$lig_err) {
if (($no_err == E_USER_ERROR) || ($no_err == E_ERROR)) {
echo "<p>Impossible d'accéeder à la ressource. Veuillez nous excusez pour le dérangement. Fin du programme.</p>";
exit;
}
}
// Configuration du gestionnaire d'erreur
set_error_handler('mon_gestionnaire_erreur');
// Stocké pour vérifier si l'utilisateur "était" connecté
$ancien_utilisateur = $_SESSION['utilisateur_ok'];
?>
<?php
if (!empty($ancien_utilisateur)) {
@$db = new mysqli('localhost', 'julien', '****', 'web');
if(mysqli_connect_errno()) {
echo "Impossible de se connecter à la base de données.";
exit;
}
$ma_requete = " SELECT * from occasion ";
$resultat = $db->query($ma_requete);
$nb_lig_resultat = $resultat->num_rows;
for($i =0; $i < $nb_lig_resultat; $i++) {
$ligne = $resultat->fetch_assoc(); ?>
<tr bgcolor="#DCDCDC" onmouseover="bgColor='lightyellow';" onmouseout="bgColor='#DCDCDC'">
<td></td>
<td class=\"cellpty\">
<?php stripslashes($ligne['id_occas']) ; ?>
<?php echo stripslashes($ligne['marque_occas']) . '</td>'; ?>
<td class="cellpty">
<?php echo stripslashes($ligne['modele_occas']) . '</td>';?>
<td class="cellpty"> <a href="#">
<?php echo stripslashes($ligne['version_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['annee_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['color_ext_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['km_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['energie_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['puissance_occas']) . '</td>';?>
<td class="cellpty"><b>
<?php echo stripslashes($ligne['prix_occas']) . '</b></td>';?>
<td> <input type='checkbox' name='b[]' value='$id_occas'></td>
</tr>
<?php $ligne = $resultat->fetch_assoc(); ?>
<tr bgcolor="#F5F5F5" onmouseover="bgColor=\'lightyellow\';" onmouseout="bgColor=\'#F5F5F5\'">
<td></td>
<td class=\"cellpty\">
<?php echo stripslashes($ligne['marque_occas']) . '</td>'; ?>
<td class="cellpty">
<?php echo stripslashes($ligne['modele_occas']) . '</td>';?>
<td class="cellpty"> <a href="#">
<?php echo stripslashes($ligne['version_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['annee_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['color_ext_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['km_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['energie_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['puissance_occas']) . '</td>';?>
<td class="cellpty"><b>
<?php echo stripslashes($ligne['prix_occas']) . '</b></td>';?>
<td> <input type='checkbox' name='b[]' value='$id_occas'></td>
</tr>
<div align="center"><input type="submit" name="supprimer" value="Supprimer"></div>
<?php } ?>
<?php }
else {
@$db = new mysqli('localhost', 'julien', '***', 'web');
if(mysqli_connect_errno()) {
echo "Impossible de se connecter à la base de données.";
exit;
}
$ma_requete = " SELECT * from occasion ";
$resultat = $db->query($ma_requete);
$nb_lig_resultat = $resultat->num_rows;
for($i =0; $i < $nb_lig_resultat; $i++) {
$ligne = $resultat->fetch_assoc(); ?>
<tr bgcolor="#DCDCDC" onmouseover="bgColor='lightyellow';" onmouseout="bgColor='#DCDCDC'">
<td></td>
<td class=\"cellpty\">
<?php echo stripslashes($ligne['marque_occas']) . '</td>'; ?>
<td class="cellpty">
<?php echo stripslashes($ligne['modele_occas']) . '</td>';?>
<td class="cellpty"> <a href="#">
<?php echo stripslashes($ligne['version_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['annee_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['color_ext_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['km_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['energie_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['puissance_occas']) . '</td>';?>
<td class="cellpty"><b>
<?php echo stripslashes($ligne['prix_occas']) . '</b></td>';?>
</tr>
<?php $ligne = $resultat->fetch_assoc(); ?>
<tr bgcolor="#F5F5F5" onmouseover="bgColor=\'lightyellow\';" onmouseout="bgColor=\'#F5F5F5\'">
<td></td>
<td class=\"cellpty\">
<?php echo stripslashes($ligne['marque_occas']) . '</td>'; ?>
<td class="cellpty">
<?php echo stripslashes($ligne['modele_occas']) . '</td>';?>
<td class="cellpty"> <a href="#">
<?php echo stripslashes($ligne['version_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['annee_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['color_ext_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['km_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['energie_occas']) . '</td>';?>
<td class="cellpty">
<?php echo stripslashes($ligne['puissance_occas']) . '</td>';?>
<td class="cellpty"><b>
<?php echo stripslashes($ligne['prix_occas']) . '</b></td>';?>
</tr>
<?php }
$resultat->free();
$db->close();
?>
Afficher la suite