Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.50 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();
  40.       $allavis = $avis->fetchAll();
  41.       $db->commit();
  42.     } catch (PDOException $exception) {
  43.       header('Location: ./avis.php');
  44.       $db->rollBack();
  45.       $notification->addAlertMessage("<b>Error : </b>".$exception->getMessage()." (".$exception->getCode().")<br>Erreur lors d'une requete, veuillez réessayer ou contactez un administrateur.", 2);
  46.       $notification->setAlert();
  47.       exit();
  48.   }
  49.  
  50.  
  51.  
  52. }
  53.  
  54. var_dump($avis);
  55.  
  56. ?>
  57.  
  58.  
  59. <?php include("./commons/header.php"); ?>
  60. <script src="../../js/wysibb.js"></script>
  61. <link rel="stylesheet" href="../css/avis.css">
  62. <body>
  63. <?php include("./commons/menu.php"); ?>
  64.   <!-- Affichage du système d'alerte -->
  65.   <?php $notification->showAlert(); ?>
  66.   <!--Formulaire-->
  67. <div class="container mt-3">
  68.     <h3>Laissez-nous votre avis</h3>
  69.     <hr>
  70.         <form method="POST" action="" enctype="multipart/form-data">
  71.           <div class="form-row">
  72.             <div class="form-group col-md-6">
  73.               <label>Nom</label>
  74.               <input type="text" class="form-control" name="nom" placeholder="Nom" >
  75.             </div>
  76.             <div class="form-group col-md-6">
  77.               <label>Prénom</label>
  78.               <input type="text" class="form-control" name="prenom" placeholder="Prénom" >
  79.             </div>
  80.           </div>
  81.           <div class="form-group">
  82.             <label>Email</label>
  83.             <input type="email" class="form-control" name="email" placeholder="Email" >
  84.           </div>
  85.           <div class="form-group">
  86.           <label>Avis</label>
  87.           <input type="text" class="form-control" name="avis" placeholder="Avis" required>
  88.           </select>
  89.         </div>
  90.         <div class="form-group">
  91.           <label>Note</label>
  92.            <div class="rate">
  93.              <input type="radio" id="star5" name="rate" value="5" />
  94.              <label for="star5" title="5">5 stars</label>
  95.              <input type="radio" id="star4" name="rate" value="4" />
  96.              <label for="star4" title="4">4 stars</label>
  97.              <input type="radio" id="star3" name="rate" value="3" />
  98.              <label for="star3" title="3">3 stars</label>
  99.              <input type="radio" id="star2" name="rate" value="2" />
  100.              <label for="star2" title="2">2 stars</label>
  101.              <input type="radio" id="star1" name="rate" value="1" />
  102.              <label for="star1" title="1">1 stars</label>
  103.           </div>
  104.                 </div>
  105.           <button type="submit" name="submit" class="btn btn-primary btn-block">Envoyer</button>
  106.         </form>
  107.     </div>
  108.  
  109. <br>
  110. <br>
  111.  
  112. <div class="container">
  113.   <h3>Avis utilisateur</h3>
  114.   <hr>
  115.   <br>
  116. <?php foreach ($allavis as $row) { ?>
  117. <div class="incoming_msg">
  118.   <div class="received_msg">
  119.     <h5><?= $row->NOM ?></h5>
  120.     <div class="received_withd_msg">
  121.       <p><?= $row->COMMENTAIRE ?></p>
  122.       <span class="time_date"></span>
  123.     </div>
  124.   </div>
  125. </div>
  126. <?php } ?>
  127. </div>
  128.  
  129. <?php include("./commons/footer.php"); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement