par
bob56@ » 24 nov. 2016, 19:53
OK çà roule, je vois que tu as un œil de lynx
Je reconnais là les pro =D> , encore merci
le code qui fonctionne:
<?php
// connexion base
include("fonctions.php"); /* ma base mes identifiants */
// On commence par récupérer les champs
$nom = htmlentities($_POST['nom'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$prenom = htmlentities($_POST['prenom'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$age = htmlentities ($_POST['age'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$adresse = htmlentities($_POST['adresse'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$email = htmlentities($_POST['email'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$telephone = htmlentities ($_POST['telephone'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$url = htmlentities ($_POST['url'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$titre = htmlentities($_POST['titre'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$date_post = htmlentities($_POST['date_post'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$nom = htmlentities($_POST['nom'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$message = htmlentities($_POST['message'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
// c'est ici qu'on vérifie si au moins un champ est vide avec OR :
if(empty($_POST['nom']) OR empty($_POST['prenom']) OR empty($_POST['age']) OR empty($_POST['adresse']) OR empty($_POST['email']) OR empty($_POST['telephone']) OR empty($_POST['url']) OR empty($_POST['titre']) OR empty($_POST['message']))
{
echo '<p><a class="champs_1" >Attention, vous avez oublié de remplir les champs suivants :</a></p><ul>';
if(empty($_POST['nom']))
{
echo '<br><li class="champs_2" >Nom</li>';
}
if(empty($_POST['prenom']))
{
echo '<br><li class="champs_2" >Prenom</li>';
}
if(empty($_POST['age']))
{
echo '<br><li class="champs_2" >Age</li>';
}
if(empty($_POST['adresse']))
{
echo '<br><li class="champs_2" >Adresse</li>';
}
if(empty($_POST['email']))
{
echo '<br><li class="champs_2" >Email</li>';
}
if(empty($_POST['telephone']))
{
echo '<br><li class="champs_2" >Téléphone</li>';
}
if(empty($_POST['url']))
{
echo '<br><li class="champs_2" >Website url</li>';
}
if(empty($_POST['titre']))
{
echo '<br><li class="champs_2" >Titre</li>';
}
if(empty($_POST['message']))
{
echo '<br><li class="champs_2" >Message</li>';
}
echo '</ul>';
// Remplacement de certains caractères spéciaux
}
else // si les variables $_POST du formulaire n'existent pas, le code ci-dessus ne s'exécute pas
{
// ici, ce que tu veux éventuellement afficher
echo '<p><a class="champs_1" >Super tous les champs sont remplis! :</a></p><ul>';
// Aucun champ n'est vide, on peut enregistrer dans la table
$bdd = "INSERT INTO `infos_tbl` (`nom`, `prenom`, `age`, `adresse`, `email`, `telephone`, `url`, `titre`, `message`, `date_post`) VALUES ( '$nom','$prenom','$age','$adresse','$email','$telephone', '$url','$titre', '$message', now() )";
if ($conn->query($bdd) === TRUE)
{
//echo "<h2 style=' color:green;'>Vos infos on été ajoutées !</h2>";
} else {
echo "<h2 style=' color:red;'>Erreur SQL insertion données:</h2> " . $bdd . "<br>" . $conn->error;
}
}
mysqli_close($conn);
?>
OK çà roule, je vois que tu as un œil de lynx :D
Je reconnais là les pro =D> , encore merci
le code qui fonctionne:
[php]<?php
// connexion base
include("fonctions.php"); /* ma base mes identifiants */
// On commence par récupérer les champs
$nom = htmlentities($_POST['nom'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$prenom = htmlentities($_POST['prenom'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$age = htmlentities ($_POST['age'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$adresse = htmlentities($_POST['adresse'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$email = htmlentities($_POST['email'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$telephone = htmlentities ($_POST['telephone'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$url = htmlentities ($_POST['url'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$titre = htmlentities($_POST['titre'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$date_post = htmlentities($_POST['date_post'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$nom = htmlentities($_POST['nom'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
$message = htmlentities($_POST['message'], ENT_QUOTES | ENT_IGNORE, "UTF-8");
// c'est ici qu'on vérifie si au moins un champ est vide avec OR :
if(empty($_POST['nom']) OR empty($_POST['prenom']) OR empty($_POST['age']) OR empty($_POST['adresse']) OR empty($_POST['email']) OR empty($_POST['telephone']) OR empty($_POST['url']) OR empty($_POST['titre']) OR empty($_POST['message']))
{
echo '<p><a class="champs_1" >Attention, vous avez oublié de remplir les champs suivants :</a></p><ul>';
if(empty($_POST['nom']))
{
echo '<br><li class="champs_2" >Nom</li>';
}
if(empty($_POST['prenom']))
{
echo '<br><li class="champs_2" >Prenom</li>';
}
if(empty($_POST['age']))
{
echo '<br><li class="champs_2" >Age</li>';
}
if(empty($_POST['adresse']))
{
echo '<br><li class="champs_2" >Adresse</li>';
}
if(empty($_POST['email']))
{
echo '<br><li class="champs_2" >Email</li>';
}
if(empty($_POST['telephone']))
{
echo '<br><li class="champs_2" >Téléphone</li>';
}
if(empty($_POST['url']))
{
echo '<br><li class="champs_2" >Website url</li>';
}
if(empty($_POST['titre']))
{
echo '<br><li class="champs_2" >Titre</li>';
}
if(empty($_POST['message']))
{
echo '<br><li class="champs_2" >Message</li>';
}
echo '</ul>';
// Remplacement de certains caractères spéciaux
}
else // si les variables $_POST du formulaire n'existent pas, le code ci-dessus ne s'exécute pas
{
// ici, ce que tu veux éventuellement afficher
echo '<p><a class="champs_1" >Super tous les champs sont remplis! :</a></p><ul>';
// Aucun champ n'est vide, on peut enregistrer dans la table
$bdd = "INSERT INTO `infos_tbl` (`nom`, `prenom`, `age`, `adresse`, `email`, `telephone`, `url`, `titre`, `message`, `date_post`) VALUES ( '$nom','$prenom','$age','$adresse','$email','$telephone', '$url','$titre', '$message', now() )";
if ($conn->query($bdd) === TRUE)
{
//echo "<h2 style=' color:green;'>Vos infos on été ajoutées !</h2>";
} else {
echo "<h2 style=' color:red;'>Erreur SQL insertion données:</h2> " . $bdd . "<br>" . $conn->error;
}
}
mysqli_close($conn);
?>[/php]