Pour insérer une critique, on va produire une page liste.php
proposant tous les films, et un lien vers une page saisie.php
permettant de saisir une critique pour ce film. Enfin, insertion.php
insère la critique dans la base.
liste.php
<html>
<body>
<?php
define("SERVEUR","localhost");
define("UTILISATEUR","david");
define("MDP","toto");
define("BASE","david");
($cnx=mysql_connect(SERVEUR,UTILISATEUR,MDP)) or (exit(mysql_error()));
mysql_select_db(BASE,$cnx) or exit(mysql_error());
($res=mysql_query("select titre from Film",$cnx)) or (exit(mysql_error()));
echo "<H1>Critiquez !</H1>";
while($nuplet=mysql_fetch_object($res)){
echo "<A HREF=\"critique.php?titre=$nuplet->titre\">";
echo $nuplet->titre;
echo "</A><BR>";
}
mysql_close($cnx);
?>
</body>
</html>
critique.php
<html>
<body>
<h1>Critique de <?= $titre?></h1>
<form action="insertion.php" method="post">
<input type=text name=auteur value="votre pseudo"><br>
<input type=text name=note value="votre note"><br>
<textarea name=contenu>
votre critique
</textarea>
<input type=hidden name="creation" value=<?= date("y:m:d")?>><br>
<input type=hidden name="titre" value="<?= $titre ?>"><br>
<input type=submit value="soumettre"><br>
</form>
</body>
</html>
insertion.php
<html>
<body>
<?php
define("SERVEUR","localhost");
define("UTILISATEUR","david");
define("MDP","toto");
define("BASE","david");
($cnx=mysql_connect(SERVEUR,UTILISATEUR,MDP)) or (exit(mysql_error()));
mysql_select_db(BASE,$cnx) or exit(mysql_error());
$commande="insert into critique(auteur,titre,note,creation,contenu) values ('$auteur','$titre',$note,'$creation','$contenu')";
($res=mysql_query($commande,$cnx)) or (exit(mysql_error()));
echo "Opération effectuée";
?>
</body>
</html>