Académique Documents
Professionnel Documents
Culture Documents
Exercice 7 p 141
Index.html:
<html>
<head>
<title>formulaire d'inscription</title>
</head>
<body>
<p align="center"> </p>
<table border="1" width="35%" id="table1" align=center>
<tr>
<td width="91">titre</td>
<td><input type="text" name="titre" size="20"></td>
</tr>
<tr>
<td width="91" height="64">résumé</td>
<td height="64"><textarea rows="2" name="resume"
cols="26"></textarea></td>
</tr>
<tr>
<td width="91">type</td>
<td><select size="1" name="type">
<option>thése</option>
<option>article</option>
<option>livre</option>
</select></td>
</tr>
<tr>
<td width="91">auteur</td>
<td><input type="text" name="auteur" size="20"></td>
</tr>
<tr>
<td colspan="2">
<p align="center"><input type="submit" value="Envoyer"
name="B1"><input type="reset" value="Rétablir" name="B2"></td>
</tr>
</table>
</form>
</body>
</html>
Insertion.php:
<?php
mysql_connect("localhost","root","");
mysql_select_db("bibliotheque");
if (mysql_query("INSERT INTO notice VALUES('','".
$_POST['titre']."','".$_POST['resume']."','".$_POST['type']."','".
$_POST['auteur']."')"))
{
echo "Votre notice dont le titre est <b><u>".
$_POST['titre']."</b></u> et l'auteur <u>".$_POST['auteur']."</u> a été saisie<br/>
<a href='saisie.php'>Retour</a>";
}
else
echo "Une erreur a été rencontrée, la notice n'a pas été inserrée.";
?>
Recherche.php:
<!--ce script a été crée par chaker ben hammouda 4sci info2-->
<html>
<head>
<title>Recherche de notice bibliographique</title>
</head>
<body>
<h2 align="center">Recherche de notice bibliographique</h2>
<?php
mysql_connect("localhost","root","");
mysql_select_db("bibliotheque3");
if (isset($_POST['titre']) AND isset($_POST['auteur']))
{
$criteres = "";
if (($_POST['titre'] != "") AND ($_POST['auteur'] != ""))
{
$criteres = " WHERE titre='".$_POST['titre']."' ".
$_POST['operateur']." auteur='".$_POST['auteur']."'";
}
else if ($_POST['titre']!="")
{
$criteres = " WHERE titre='".$_POST['titre']."'";
}
else if ($_POST['auteur']!="")
{
$criteres = " WHERE auteur='".$_POST['auteur']."'";
}
$recherche = mysql_query("SELECT * FROM notice".
$criteres."ORDER BY id");
if ($recherche)
{
?>
<table align="center" border=1>
<tr><td>Id
notice</td><td>Titre</td><td>Résumé</td><td>Type</td><td>Auteur</td></tr>
<?php
while($notice = mysql_fetch_array($recherche))
{
echo "<tr><td>".$notice['id']."</td><td>".
$notice['titre']."</td><td>".$notice['resume']."</td><td>".$notice['type']."</td><td>".
$notice['auteur']."</td></tr>";
}
?>
</table>
<center><a href="recherche.php">Rechercher</a></center>
<?php
}
else
echo "Aucune notice ne correspond à votre recherche";
}
else
{
?>
<form method="POST" action="recherche.php">
<table border=1 align="center">
<tr><td>Opérateur</td><td>Critères</td><td>Valeurs</td></tr>
<tr><td rowspan="2"><input type="radio" name="operateur"
value="AND" checked>AND</input><br/>
<input type="radio" name="operateur"
value="OR">OR</input>
</td><td>Titre</td><td><input type="text"
name="titre"/></td></tr>
<tr><td>Auteur</td><td><input type="text"
name="auteur"/></td></tr>
<tr><td colspan=3 align="center"><input type="submit"
value="Valider"/><input type="reset" value="Annuler"/></td></tr>
</table>
<?php } ?>
</body>
Exercice 8 p 142
<body>
</body>
</html>
Sauvegarder.php
<html>
<body>
<?
mysql_connect("localhost","root","");
mysql_select_db("dbcabinet");
$req="select * from inscription where email='$email'";
$r=mysql_query($req);
if((mysql_num_rows($r))=0)
{
//l'email n'existe pas dans la base donc on peut faire l'insertion
echo ($module);
$choix=implode("*",$module);
echo ("choix=".$choix);
$req2="insert into inscription(nomprenom,email,modules)
values('$nom','$email','$choix')";
if(!(mysql_query($req2)))
echo "inscription échouée";
else{
$nb_HTML=mysql_num_rows(mysql_query("select *
from inscription where modules like \"%HTML%\""));
$nb_JS=mysql_num_rows(mysql_query("select * from
inscription where modules like \"%JavaScript%\""));
$nb_PHP1=mysql_num_rows(mysql_query("select *
from inscription where modules like \"%PHP1%\""));
$nb_PHP2=mysql_num_rows(mysql_query("select *
from inscription where modules like \"%PHP2%\""));
$nb_XML=mysql_num_rows(mysql_query("select *
from inscription where modules like \"%XML%\""));
?>
<table border=1>
<tr><td>Modules</td><td>Nombre d'inscriptions</td>
<tr><td>HTML</td><td><? echo $nb_HTML; ?></td></tr>
<tr><td>JavaScript</td><td><? echo $nb_JS; ?></td></tr>
<tr><td>PHP1</td><td><? echo $nb_PHP1; ?></td></tr>
<tr><td>PHP2</td><td><? echo $nb_PHP2; ?></td></tr>
<tr><td>XML</td><td><? echo $nb_XML; ?></td></tr>
</table>
<?
}}
else{
echo (mysql_num_rows(mysql_query($req1)));
echo "email deja existant";
}
?>
</body>
</html>