File "addAvis-20250608042006.php"
Full Path: /home/asmplong/www/php/addAvis-20250608042006.php
File size: 1.9 KB
MIME-type: text/x-php
Charset: utf-8
<?php
session_start();
include('../admin/inc.conec.php');
include('../admin/inc.fonctions.php');
include('../admin/inc.config.php');
$errorMSG = "";
// NAME
if (empty($_POST["nom"])) {
$errorMSG = "Veuillez saisir votre nom<br />";
} else {
$nom = $_POST["nom"];
}
// EMAIL
if (empty($_POST["lieu"])) {
$errorMSG .= "Veuillez saisir un lieu<br />";
} else {
$lieu = $_POST["lieu"];
}
// EMAIL
if (empty($_POST["rating"])) {
$errorMSG .= "Veuillez attribuer une note<br />";
} else {
$rating = $_POST["rating"];
}
// MESSAGE
if (empty($_POST["message"])) {
$errorMSG .= "Veuillez saisir un message<br />";
} else {
$message = addslashes($_POST["message"]);
}
$EmailTo = $config_email;
$Subject = "Avis à valider - [SITE DOMOTEC]";
$ref = rand(10000, 99999);
$sql_verif_id = "SELECT id FROM avis WHERE id='$id'";
$req_verif_id = mysqli_query($connect,$sql_verif_id);
while(mysqli_fetch_array($req_verif_id) == TRUE)
{
$ref = rand(10000, 99999);
}
// Ajout en BDD
$sql_insert = "INSERT INTO avis SET
id='$ref',
titre ='$nom',
description='$lieu',
categ ='$rating',
contenu ='$message',
date=NOW()";
$req_insert = mysqli_query($connect,$sql_insert);
if($req_insert)
{
// prepare email body text
$Body = "";
$Body .= "Nom : ";
$Body .= $nom;
$Body .= "\n";
$Body .= "Lieu : ";
$Body .= $lieu;
$Body .= "\n";
$Body .= "Note :";
$Body .= $rating;
$Body .= "/5 \n";
$Body .= "Avis : \n";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, utf8_decode($Body), "From: ".$config_email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Un problème est survenu";
} else {
echo $errorMSG;
}
}
}
?>