et merci d'avance pour l'aide attendu.
Mon problème
point de départ pour récupérer un bon email et l'insérer dans la bdd si celui-ci est OK.
j'ai bien essayé de diverses manières, mais sans arriver au résultat escompté
si erreur lors de la saisie, afficher juste le message $email : adresse non valide ! sans inscription dans la bdd
voilà le script:
<?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 ===============================================================================
if($email = ($_POST['email'])){
// Supprime tous les caractères illégaux du courrier électronique
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Email valide
if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$email =($_POST['email']);
echo("<br><a class='champs_3'>$email : est une adresse e-mail valide!</a><br>");
} else {
$email =($_POST['email']);
echo("<br><a class='champs_3'> $email : adresse non valide !</a><br>");
}
} // Email =============================================================================
$telephone =($_POST['telephone']);
$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" >Compléter 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>';
}
else // si les variables $_POST du formulaire n'existent pas, le code ci-dessus ne s'exécute pas
{
// ici, ce que je 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);
?>