review.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. $host = "provalgk.beget.tech";
  3. $username = "provalgk_user";
  4. $password = "Qwer123.";
  5. $database = "provalgk_user";
  6. $review = $_POST["review"];
  7. $rating = $_POST["rating"];
  8. $mysql = new mysqli($host, $username, $password, $database);
  9. if($mysql->connect_error){
  10. die("Ошибка подключения". $mysql->connect_error);
  11. }
  12. session_start();
  13. $id = $_SESSION['id'];
  14. $query = "INSERT INTO reviews (review, rating, id_user) VALUES ('$review', '$rating', '$id')";
  15. $result = $mysql->query($query);
  16. if(!$result){
  17. echo "Что то не так" . $mysql->error;
  18. }
  19. else{
  20. session_start();
  21. $message = "Пользователь ".$_SESSION['login']. " оставил отзыв: ".$review.". Оценив сайт на " .$rating. "звёзд";
  22. $query = "SELECT * FROM Login Where role = 1";
  23. $result = mysqli_query($mysql, $query);
  24. While($rivews = mysqli_fetch_assoc($result)){
  25. $from = "provalenkoludmila@gmail.com";
  26. $subject = "Новый отзыв на сайте";
  27. $subject = "=?utf-8?B?".base64_encode($subject)."?=";
  28. $headers = "From: $from\r\nReply-to: $from\r\nContent-type: text/html; charset=utf-8\r\n";
  29. mail($rivews['email'], $subject, $message, $headers);
  30. }
  31. echo "<script>window.location.href = 'indexforuser.html';</script>";
  32. }
  33. ?>