ABBASSI Kamel
Correction TP Partie 1
Tp partie
1
Fichier : index.php
Auteur : Mr. ABBASSI Kamel
?>
</body>
</html>
Correction TP Partie 1 2 Enseignant : Mr. ABBASSI Kamel
Fichier : menu.php
Auteur : Mr. ABBASSI Kamel
<?php
//fonction pour la connexion au serveur et la base
function connexion(){
mysql_connect('localhost','root','') or die('Impossible d\'accerder auserveur');
mysql_select_db('scoop') or die('Imppossible d\'acceder à la base');
}
function alerte($ch)
{
$code="<script type=\"text/javascript\">";
$code.="alert('$ch');";
$code.="</script>";
echo $code;
}
function deconnexion()
{
mysql_close();
}
?>
Correction TP Partie 1 3 Enseignant : Mr. ABBASSI Kamel
Fichier : GestionProduits.php
Auteur : Mr. ABBASSI Kamel
<body>
<center> <h4>Bienvenue Administrateur </h4></center>
<?php include('menu.php') ?>
</body>
</html>
Fichier : ajouter.php
Auteur : Mr. ABBASSI Kamel
Fichier : chercher.php
Auteur : Mr. ABBASSI Kamel
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Chercher un produit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include('menu.php');
include('fonctions.php'); ?>
<center>
<h3>Rechercher un produit</h3>
Correction TP Partie 1 5 Enseignant : Mr. ABBASSI Kamel
</center>
<?php
if(isset($_POST['mc'])) // variable existant
{
if(!empty($_POST['mc'])) //champs non vide
{
connexion();
$sql1="select * from produit where ref='".$_POST['mc'].
"' or nom='".$_POST['mc']."' or marque='".$_POST['mc'].
"' or prix='".$_POST['mc']."' or cat='".$_POST['mc']."'";
<?php
} // fin de while
echo "</table>";
deconnexion();
} // fin de if de champs vide
else // si le champs mc est vide
alerte('Taper un mot cle');
} //fin de if de variable existants
?>
</body>
</html>
Correction TP Partie 1 6 Enseignant : Mr. ABBASSI Kamel
Fichier : modifier.php
Auteur : Mr. ABBASSI Kamel
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Modifier un produit</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include('menu.php'); include('fonctions.php');
if(isset($_GET['reference']))
{
connexion();
$sql1="select * from produit where ref='".$_GET['reference']."'";
$r1=mysql_query($sql1);
while($enreg=mysql_fetch_array($r1))
{
?>
<center>
<h3>Modification du produit : <?php echo $_GET['reference'] ?></h3>
<form action="modifier.php" method="post">
<table border="1">
<tr><td bgcolor="#00FF99">Nom</td><td><input type="text" name="nom"
value="<?php echo $enreg['nom']; ?>"></td></tr>
<tr><td bgcolor="#00FF99">Marque</td><td><input type="text"
name="marque" value="<?php echo $enreg['marque']; ?>"></td></tr>
<tr><td bgcolor="#00FF99">Prix</td><td><input type="text" name="prix"
value="<?php echo $enreg['prix']; ?>"></td></tr>
</table>
<input type="submit" value="Modifier"> <input type="reset" value="Annuler">
<input type="hidden" name="reference" value="<?php echo $_GET['reference']; ?>">
</form>
</center>
<?php
deconnexion();
}
}
// mise à jour de produit
if(isset($_POST['nom']) and isset($_POST['marque']) and isset($_POST['prix']))
{
connexion();
alerte('connexion avec succés');
$sql="update produit set nom='".$_POST['nom']."', marque='".$_POST['marque']."',
prix='".$_POST['prix']."' where ref= '".$_POST['reference']."'";
mysql_query($sql);
alerte('La modification est fait avec succés');
Correction TP Partie 1 7 Enseignant : Mr. ABBASSI Kamel
?>
</body>
</html>
Fichier : supprimer.php
Auteur : Mr. ABBASSI Kamel
<body>
<?php
include('fonctions.php');
connexion();
$sql="delete from produit where ref='".$_GET['reference']."'";
mysql_query($sql) or die('Erreur de supprission de produit');
echo "<center>Le produit :".$_GET['reference']." est supprimé avec succés</center>";
?>
</body>
</html>
Fichier : lister.php
Auteur : Mr. ABBASSI Kamel
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Lister trier les produits</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include('menu.php'); include('fonctions.php');?>
<center>
<p>
<form name="trie" action="lister.php" method="post">
Catégorie <input type="radio" name="t" value="cat">
Nom <input type="radio" name="t" value="nom">
Marque <input type="radio" name="t" value="marque">
Prix <input type="radio" name="t" value="prix">
Correction TP Partie 1 8 Enseignant : Mr. ABBASSI Kamel
</p>
<p>
<input type="submit" value="Trier"></p>
</form>
<?php
if(isset($_POST['t']))
{
switch($_POST['t']){
case 'cat' :trie('cat');break;
case 'marque' :trie('marque');break;
case 'nom' :trie('nom');break;
case 'prix' :trie('prix');break;
}
}
function trie($var){
connexion();
$sql="select * from produit order by ".$var;
$resultat=mysql_query($sql);
echo "<table border=1>";
echo "<tr><th bgcolor=\"yellow\">Réference</th><th bgcolor=\"yellow\">Catégorie</th><th
bgcolor=\"yellow\">Nom</th><th bgcolor=\"yellow\">Prix</th></tr>";
while($enreg=mysql_fetch_array($resultat)){
echo"<tr><td>".$enreg['ref']."</td><td>".$enreg['cat']."</td><td>".$enreg['nom']."</td><td>".$enreg['prix']."<
/td></tr>";
}
echo "</table>";
}
?>
</center>
</body>
</html>