Vous êtes sur la page 1sur 10

Correction

Exercice n° 1 :

<HTML>

<HEAD>

<TITLE>TP 2 EX1</TITLE>

</HEAD>

<BODY>

<table border="1">

<tr><td>Nom</td><td>Adresse</td><td>Ville</td><td>Pays</td></tr>

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("SELECT * FROM clients");

while ($voir = mysql_fetch_array($result))

echo"<tr>";

echo"<td>".$voir['nom']."</td>";

echo"<td>".$voir['adresse']."</td>";

echo"<td>".$voir['ville']."</td>";

echo"<td>".$voir['pays']."</td>";

echo"</tr>";

?>

</table>
</BODY>

</HTML>

Exercice n° 2 :

****page affichage des clients****

<HTML>

<HEAD>

<TITLE>TP 2 EX1</TITLE>

</HEAD>

<BODY>

<table>

<form action="Ex2_1.php" method="POST">

<select name="code">

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("SELECT * FROM clients");

while ($voir = mysql_fetch_array($result))

echo"<option value=".$voir['code'].">".$voir['nom']."</option>";

?>

</select>

<input type="submit" value="Consulter">

</form>

</BODY>

</HTML>

****page affichage des commandes par client****

<HTML>

<HEAD>

<TITLE>Suite Ex2</TITLE>
</HEAD>

<BODY>

<table border="1">

<tr>

<td>Numero commande</td>

<td>Date Commande</td>

<td>Total</td>

</tr>

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("SELECT * FROM commandes where (codeclient like '$_POST[code]')");

while ($voir = mysql_fetch_array($result))

echo"<tr>";

echo"<td>".$voir['numerocmd']."</td>";

echo"<td>".$voir['datecmd']."</td>";

echo"<td>".$voir['totalcmd']."</td>";

echo"</tr>";

?>

</table>

</body>

</html>

Exercice n° 3 :

****page saisie des informations du produit****

<HTML>

<HEAD>

<TITLE>Ajout de produit</TITLE>

</HEAD>
<BODY>

<h2 align=center>Ajout produit</h2>

<form method="POST" action="ajout.php">

<table>

<tr>

<td>Référence</td><td><input type="text" name="reference"></td></tr>

<td>Désignation</td><td><input type="text" name="designation"></td></tr>

<td>Catégorie</td><td><select size=1 name="codecat">

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("SELECT * FROM categories");

while ($voir = mysql_fetch_array($result))

echo"<option value=".$voir['code'].">".$voir['designation']."</option>";

?>

</select>

</td>

</tr>

<td>Prix</td> <td><input name="prix"></td></tr>

<tr>

<td><input type=submit name=B1 value="Ajouter"></td>

<td><input type=reset name=B2 value="Rétablir"></td>

</tr>

</table>

</form>

</body>

</html>
****page ajout.php****

<HTML>

<HEAD>

<TITLE>suite Ex3</TITLE>

</HEAD>

<BODY>

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("SELECT * FROM produits WHERE (reference = '$_POST[reference]')");

if (mysql_num_rows($result)==0)

$result=mysql_query("insert into produits (reference,designation,prix,codecategorie) values


('$_POST[reference]','$_POST[designation]','$_POST[prix]','$_POST[codecat]')");

echo("produit a été ajouté dans la base");

else

echo("produit existe dans la base");

?>

</table>

</body>

</html>

Exercice n° 4 :

****page liste de produits****

<html>

<head>

<title>liste produits</title>

</head>
<body>

<table border="1">

<tr>

<td>Référence</td>

<td>Désignation</td>

<td>Catégorie</td>

<td>Prix</td>

<td colspan=2>Opération</td>

</tr>

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("SELECT * FROM produits");

while ($voir = mysql_fetch_array($result))

echo"<tr>";

echo"<td>".$voir['reference']."</td>";

echo"<td>".$voir['designation']."</td>";

$resultat=mysql_query("select designation from categories where (code=".


$voir['codecategorie'].")");

$execut=mysql_fetch_array($resultat);

echo"<td>".$execut['designation']."</td>";

echo"<td>".$voir['prix']."</td>";

echo"<td>"."<a href=modifierproduit.php?ref=".$voir['reference'].">modifier</a></td>";

echo"<td>"."<a href=supprimerproduit.php?ref=".$voir['reference'].">supprimer</a></td>";

echo"</tr>";

?>

</table>
</body>

</html>

****page modifier produit****

<html>

<head>

<title>Modifier produit</title>

</head>

<body>

<h2>Modifier produit</h2>

<?

If(!isset($_POST[‘B1’]){

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$res = mysql_query("SELECT * FROM produits where (reference=$_GET[ref])");

while ($exe = mysql_fetch_array($res))

echo"<form method='POST' action=''>

<input type='hidden' name='ref' value='$exe[0]'>

<table>

<tr>

<td>Désignation</td>

<td><input type='text' name='designation' value='$exe[1]'></td></tr>

<tr><td>Prix</td><td><input name='prix' value='$exe[prix]'></td></tr>";

?>

<tr>

<td><input type=submit name=B1 value="Modifier"></td>

<td><input type=reset name=B2 value="Rétablir"></td>

</tr>

</table>
</form>

<? } else{

$requete="UPDATE produits SET designation='$designation', prix='$prix' WHERE


(reference=$_GET[ref])";

$excution=mysql_db_query("base_test",$requete); }

?>

</body>

</html>

****page supprimer produit****

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result = mysql_query("delete FROM produits where reference=$_GET[ref]");

?>

Exercice n° 5 :

****page affichage par catégorie****

<HTML>

<HEAD>

<TITLE>affichage catégorie</TITLE>

</HEAD>

<BODY>

<table border=1>

<tr>

<td>Désignation catégorie</td>

<td>Nombre de produit</td>

</tr>

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$res = mysql_query("SELECT categories.designation, count(*),categories.code FROM produits,


categories where (categories.code=produits.codecategorie) Group By categories.code");
// GroupBy pour éviter la duplication

while ($voir = mysql_fetch_array($res))

echo"<tr><td><a href=liste.php?ref=".$voir[2].">".$voir[0]."</a></td>";

echo"<td>".$voir[1]."</td></tr>";

?>

</table>

</BODY>

</HTML>

****page affichage produit par catégorie****

<html>

<head>

<title>liste produits</title>

</head>

<body>

<table border="1">

<tr>

<td>Référence</td>

<td>Désignation</td>

<td>Prix</td>

</tr>

<?

mysql_connect("localhost", "root", "");

mysql_select_db("base_test");

$result=mysql_query("select * from produits where (codecategorie=".$_GET[ref].")");

while ($voir = mysql_fetch_array($result))

echo"<tr>";
echo"<td>".$voir['reference']."</td>";

echo"<td>".$voir['designation']."</td>";

echo"<td>".$voir['prix']."</td>";

echo"</tr>";

?>

</table>

</body>

</html>

Vous aimerez peut-être aussi