Académique Documents
Professionnel Documents
Culture Documents
TP PHP N°3
Objectifs :
Dans ce TP on se propose d’apprendre comment Manipuler des données (Insérer, modifier,
supprimer et afficher) dans une table d’une BD
Travail demandé :
1. Créer la base de donnée « Bibliotheque ». Dans cette base créer la table « Livre » ayant la
structure suivante :
Zone contenant les boutons de navigation pour afficher les différentes pages
du site
<nav>
<a href="ajout.html" target="aff">Ajouter un livre</a>
<a href="modifier.html" target="aff">Modifier un livre</a>
<a href="Supprimer.html" target="aff">Supprimer un livre</a>
<a href="afficher.php" target="aff">Afficher les livres</a>
</nav>
?>
$res1= mysqli_query($cnx,$req1); }
else{
if(mysqli_num_rows($res1)==0){ echo"Le livre a été supprimé avec succès";
die( "L'identifiant du livre est mysqli_close($cnx);
incorrecte"); }
} }?>
Afficher.php
<?php <th>Auteur</th>
$cnx=mysqli_connect("localhost","root" <th>Editeur</th>
,"","bibliotheque"); <th>Date de parution</th>
$req="SELECT* FROM livre"; </tr>
$res=mysqli_query($cnx,$req); ";
echo" while($l=mysqli_fetch_assoc($res)){
<!DOCTYPE html>
<html> echo"<tr>
<head> <td>".$l['Id_liv']."</td>
<link rel='stylesheet' type='text/css' <td>".$l['Nom_liv']."</td>
media='screen' href='style2.css'></head> <td>".$l['Auteur_liv']."</td>
<body> <td>".$l['Editeur_liv']."</td>
<h1>Liste des livres</h1> <td>".$l['Date_parution']."</td>
<table> </tr>";
<tr> }
<th>Identifiant</th> echo"</table></body></html>";
<th>Nom du livre</th> ?>
« Style.css »
body{ a{
display: flex; text-align: center;
margin: 10px; width: 300px;
padding: 10px; height: 50px;
} background-color: rgba(94, 156,
main{ 226, 0.418);
width: 70%; border-radius: 10px;
height: 480px; color:rgb(160, 8, 59);
border: 2px solid rgb(5, 182, 5); font-size: x-large;
border-radius: 10px; text-decoration: none;
margin: 10px; padding: 10px;
} margin-top: 25px;
nav{ margin-bottom: 25px;
width: 30%; transition: width 1s;
height: 480px; }
border: 2px solid blueviolet; a:hover{
margin: 10px; width: 350px;
border-radius: 10px; background-color: rgb(16, 219, 43);
display: flex; color: azure;
flex-direction: column;
align-items: center; }
justify-content: center;
}
« Style2.css »
th,tr,td{ th{
width: 150px; text-align: center;
height: 50px; background-color:aquamarine;}
border: none; td{
background-color:azure; background-color: azure;
margin: 5px; }
padding: 2px; h1{
text-align: center;
} color: green;
}
Rappel :
Les fonctions PHP à utilisées:
Le rôle de mysqli_affected_rows est donc de retourner le nombre de lignes d'une table qui ont
été modifiées (ajoutées, mises à jour ou supprimées) par la dernière requête exécutée via
mysqli_query. Cela peut être utile pour vérifier si une requête a été exécutée avec succès ou
pour connaître le nombre de lignes affectées par une requête particulière.