Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.45 KB | None | 0 0
  1. <?php require_once ("./req/core.php");
  2.  
  3.  
  4.  
  5. if(isset($_POST['submit'])){
  6.   if(!empty($_POST['nom']) && !empty($_POST['prenom']) && !empty($_POST['email']) && !empty($_POST['avis']) && !empty($_POST['rate'])){
  7.     // Convertit les caractères spéciaux en entités HTML
  8.     $nom = htmlspecialchars($_POST['nom']);
  9.     $prenom = htmlspecialchars($_POST['prenom']);
  10.     $email = htmlspecialchars($_POST['email']);
  11.     $avis = htmlspecialchars($_POST['avis']);
  12.     $note = htmlspecialchars($_POST['rate']);
  13.         try{
  14.           $db->beginTransaction();
  15.           $ajout = $db->prepare("INSERT INTO AVIS SET NOM = ?, PRENOM = ?, EMAIL = ?, COMMENTAIRE = ?, NOTE = ?");
  16.           $ajout->execute(array($nom,$prenom, $email, $avis, $note));
  17.           $db->commit();
  18.         } catch (PDOException $exception) {
  19.           $db->rollBack();
  20.           $notification->addAlertMessage("<b>Error : </b>".$exception->getMessage()." (".$exception->getCode().")<br>Erreur lors d'une requete, veuillez réessayer ou contactez un administrateur.", 2);
  21.           $notification->setAlert();
  22.         }
  23.         $notification->addAlertMessage("Votre avis à bien été pris en compte !", 0);
  24.         $notification->setAlert();
  25.         header('Location: ./avis.php');
  26.         exit();
  27.  
  28.   }
  29.     $notification->setAlert();
  30. }
  31.  
  32. if(isset($_GET['id']) and is_numeric($_GET['id'])) {
  33.   $id = intval($_GET['id']);
  34.   echo "string";
  35.   exit();
  36.     try{
  37.       $db->beginTransaction();
  38.       $avis = $db->prepare('SELECT * FROM AVIS ORDER BY ID');
  39.       $avis->execute(array($id));
  40.       $db->commit();
  41.     } catch (PDOException $exception) {
  42.       $db->rollBack();
  43.       $notification->addAlertMessage("<b>Error : </b>".$exception->getMessage()." (".$exception->getCode().")<br>Erreur lors d'une requete, veuillez réessayer ou contactez un administrateur.", 2);
  44.       $notification->setAlert();
  45.   }
  46.  
  47.    $allavis = $avis->fetchAll();
  48.  
  49. }
  50.  
  51. var_dump($avis);
  52.  
  53. ?>
  54.  
  55.  
  56. <?php include("./commons/header.php"); ?>
  57. <script src="../../js/wysibb.js"></script>
  58. <link rel="stylesheet" href="../css/avis.css">
  59. <body>
  60. <?php include("./commons/menu.php"); ?>
  61.   <!-- Affichage du système d'alerte -->
  62.   <?php $notification->showAlert(); ?>
  63.   <!--Formulaire-->
  64. <div class="container mt-3">
  65.     <h3>Laissez-nous votre avis</h3>
  66.     <hr>
  67.         <form method="POST" action="" enctype="multipart/form-data">
  68.           <div class="form-row">
  69.             <div class="form-group col-md-6">
  70.               <label>Nom</label>
  71.               <input type="text" class="form-control" name="nom" placeholder="Nom" >
  72.             </div>
  73.             <div class="form-group col-md-6">
  74.               <label>Prénom</label>
  75.               <input type="text" class="form-control" name="prenom" placeholder="Prénom" >
  76.             </div>
  77.           </div>
  78.           <div class="form-group">
  79.             <label>Email</label>
  80.             <input type="email" class="form-control" name="email" placeholder="Email" >
  81.           </div>
  82.           <div class="form-group">
  83.           <label>Avis</label>
  84.           <input type="text" class="form-control" name="avis" placeholder="Avis" required>
  85.           </select>
  86.         </div>
  87.         <div class="form-group">
  88.           <label>Note</label>
  89.            <div class="rate">
  90.              <input type="radio" id="star5" name="rate" value="5" />
  91.              <label for="star5" title="5">5 stars</label>
  92.              <input type="radio" id="star4" name="rate" value="4" />
  93.              <label for="star4" title="4">4 stars</label>
  94.              <input type="radio" id="star3" name="rate" value="3" />
  95.              <label for="star3" title="3">3 stars</label>
  96.              <input type="radio" id="star2" name="rate" value="2" />
  97.              <label for="star2" title="2">2 stars</label>
  98.              <input type="radio" id="star1" name="rate" value="1" />
  99.              <label for="star1" title="1">1 stars</label>
  100.           </div>
  101.                 </div>
  102.           <button type="submit" name="submit" class="btn btn-primary btn-block">Envoyer</button>
  103.         </form>
  104.     </div>
  105.  
  106. <br>
  107. <br>
  108.  
  109. <div class="container">
  110.   <h3>Avis utilisateur</h3>
  111.   <hr>
  112.   <br>
  113. <?php foreach ($allavis as $row) { ?>
  114. <div class="incoming_msg">
  115.   <div class="received_msg">
  116.     <h5><?= $row->NOM ?></h5>
  117.     <div class="received_withd_msg">
  118.       <p><?= $row->COMMENTAIRE ?></p>
  119.       <span class="time_date"></span>
  120.     </div>
  121.   </div>
  122. </div>
  123. <?php } ?>
  124. </div>
  125.  
  126. <?php include("./commons/footer.php"); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement