J'ai créé un livre d'or.
Je valide les données entrées en appliquant une formule Javascript.
Si le nom est manquant j'ai un message.
Comment suite à ce message bloquer les enregistrements dans la table des messages
Merci
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Livre d'Or</title>
<!--Indique une feuille de style interne -->
<style type="text/css">
<!--Couleur des Liens -->
a:link{color:red};
a:visited{color:blue};
a:hover{color:black};
a:active{color:green};
body{
background-color:"#B2B2B2";
text-align:center
}
table{
background-color: "#B2B2B2";
}
<!--Indique la position dans une cellule du tableau -->
td.gauche{text-align:left}
td.droite{text-align:right}
td.centre{text-align:center}
.red{color:red}
</style>
</head>
<SCRIPT Language="JavaScript">
function Controle()
{
if(document.test.txtName.value=='')
{
alert('Veuillez renseigner la zone Nom ');
document.test.txtName.focus();
}
}
</script>
<body>
<!-- Barre de Navigation -->
<table style="padding: 0px; width: 90%; margin-left: auto; margin-right: auto; ;"
border="0" cellpadding="2" cellspacing="2">
<tr>
<td
style="width: auto; text-align: center; color: rgb(102, 0, 0);"><a
href="index.php" style="text-decoration: none;font-size: 20px;">Accueil</a></td>
<td
style="width: auto; text-align: center; color: rgb(102, 0, 0);"><a
href="Themes.php" style="text-decoration: none;font-size: 20px;">Galerie</a></td>
<td
style="width: auto; text-align: center; color: rgb(102, 0, 0);"><a
href="Auteur.php" style="text-decoration: none;font-size: 20px;">Auteur</a></td>
<td
style="width: auto; text-align: center; color: rgb(102, 0, 0);font-size : 20px;">Livre d'Or</td>
<td
style="width: auto; text-align: center; color: rgb(102, 0, 0);font-size: 20px;"><a
href="liens.php" style="text-decoration: none;">Liens</a></td>
</tr>
</table>
<!-- -->
<h1>Bienvenue sur mon livre d'or</h1>
<p> </p>
<?php
include ("connection.php");
//Initialisation des variables
$table="tbllivredor";
//Le message sera reçu par l'intermédiaire du serveur de l'hébergeur (ex Apache)
$page = $_SERVER ["PHP_SELF"];
$adresseemail="[email protected]";
$name="";
$city="";
$country="";
$email="";
$url="";
$note="";
$comment="";
$result = mysql_query("SELECT * FROM $table ORDER BY id_message DESC");
$total=mysql_numrows($result);
?>
<!-- -->
<table border="1" width="50%" cellspacing="0" cellpadding="5">
<tr>
<td class="gauche">[<a href="#form">Signer le Livre d'Or <SPAN Class="Red">en cliquant ici</SPAN></a>]</td>
<td class="droite">[<b>Au total : <? echo $total; ?> messages</b>]
</tr>
</table>
<!-- -->
<?php
while ($val = mysql_fetch_array($result))
{
?>
<p> </p>
<table border="0" width="50%" cellspacing="0">
<tr>
<td colspan="2" class="gauche"><b>De : </b>
<?= $val["nom"]; ?>
<?php
if ($val["email"]) { ?> <A href="mailto:<?= $val["email"]; ?>"><small>[Écrivez moi] </small></A><?php } ?>
<?php
if ($val["site"]!="http://") { ?><A href="<?= $val["site"]; ?>"><small>[Site Web] </small></A><?php } ?>
</td>
</tr>
<tr>
<td class="gauche">
<?php
if($val["ville"]){echo "<b>Ville : </b>".$val['ville']." "; } ?></td>
<td class="droite"><?php if($val["pays"]){echo "<b>Pays : </b>".$val['pays']."<br>"; } ?></td>
</tr>
<tr>
<td colspan="2"><b>Inscrit le : </b> <?= $val["date"]; ?></td>
</tr>
<tr>
<td colspan="2"><hr><b>Message : </b>
<?= str_replace("<","<",$val["commentaire"]); ?></td>
</tr>
</table>
<?php
}
?>
<!-- -->
<p><a name="form"></a> </p>
<!--Création du formulaire-->
<form method="post" action="<?= $page ?>" name="test">
<fieldset><legend>Laissez nous votre commentaire</legend>
<div style="text-align:center">
<table cellpadding="3">
<tr>
<td colspan="4">Nom <input name="txtName" value="" size="15" maxlength="30"></td>
<td colspan="4">Ville <input name="txtCity" size="15" maxlength="30"></td>
<td colspan="4">Pays <select name="lstCountry">
<option value="France" selected>France
<option value="Grande Bretagne">Grande Bretagne
<option value="Canada">Canada
<option value="Italie">Italie
<option value="Belgique" >Belgique
<option value="Suisse">Suisse
<option value="Luxembourg">Luxembourg
<option value="USA">USA
<option value="Autre">Autre
</select>
</td>
</tr>
<tr>
<td> </td>
<td colspan="5">E-mail<br><input name="txtEmail" size="20" maxlength="30"></td>
<td colspan="5">Site<br><input name="txtUrl" value="http://" size="20" maxlength="30">
</td>
<td> </td>
</tr>
<tr>
<td colspan="12"><br><textarea name="txaComment" rows="10" cols="55"></textarea>
Code:
<br><br><input type="button" value="Signer le livre" name="bntSoumet" onClick="javascript:Controle();"><input type="reset" value="Effacer"><br>
</td>
</tr>
</table>
</div>
</fieldset>
</form>
<!-- -->
<?php
if (isset($_POST["txtName"])) $name=htmlspecialchars(stripslashes($_POST["txtName"]), ENT_QUOTES);
if (isset($_POST["txtCity"])) $city=htmlspecialchars(stripslashes($_POST["txtCity"]), ENT_QUOTES);
if (isset($_POST["lstCountry"])) $country=htmlspecialchars(stripslashes($_POST["lstCountry"]), ENT_QUOTES);
if (isset($_POST["txtEmail"])) $email=htmlspecialchars(stripslashes($_POST["txtEmail"]), ENT_QUOTES);
if (isset($_POST["txtUrl"])) $url=htmlspecialchars(stripslashes($_POST["txtUrl"]), ENT_QUOTES);
if (isset($_POST["txaComment"])) $comment=htmlspecialchars(stripslashes($_POST["txaComment"]), ENT_QUOTES);
?>
<?php
$date = date("d/m/y");
$email=str_replace("@","@",$email); //cryptage du signe @
$query = "INSERT INTO $table(date,nom,ville,pays,email,site,commentaire)";
$query .= " VALUES('$date','$name','$city','$country','$email','$url','$comment')";
$result = mysql_query($query);
?>
<p id="rep">Merci d'avoir signé le livre d'or</p>
<p>
Le message sera rajouté dès que possible
</p>
<p>
<a href="<?= $page ?>">-- Retourner sur le livre d'or --</a>
</p>
</BODY>
</HTML>