Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. |rating_id|seller_id|rate|customer_id|
  2. --------------------------------------
  3. | | | | |
  4. | | | | |
  5. --------------------------------------
  6.  
  7. |rating_id|seller_id|rate|customer_id|
  8. --------------------------------------
  9. | 1 | 0 | 4 | 29 |
  10. | | | | |
  11. --------------------------------------
  12.  
  13. <fieldset id="seller_rate" class="rating">
  14. <input type="hidden" name="seller_id" id="<?php echo $_GET['seller_id']; ?>" value="<?php echo $_GET['seller_id']; ?>"/>
  15. <input class="stars" type="radio" id="star5" name="rating" value="5" />
  16. <label class = "full" for="star5" title="Awesome - 5 stars"></label>
  17. <input class="stars" type="radio" id="star4half" name="rating" value="4.5" />
  18. <label class="half" for="star4half" title="Pretty good - 4.5 stars"></label>
  19. <input class="stars" type="radio" id="star4" name="rating" value="4" />
  20. <label class = "full" for="star4" title="Pretty good - 4 stars"></label>
  21. <input class="stars" type="radio" id="star3half" name="rating" value="3.5" />
  22. <label class="half" for="star3half" title="Meh - 3.5 stars"></label>
  23. <input class="stars" type="radio" id="star3" name="rating" value="3" />
  24. <label class = "full" for="star3" title="Meh - 3 stars"></label>
  25. <input class="stars" type="radio" id="star2half" name="rating" value="2.5" />
  26. <label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label>
  27. <input class="stars" type="radio" id="star2" name="rating" value="2" />
  28. <label class = "full" for="star2" title="Kinda bad - 2 stars"></label>
  29. <input class="stars" type="radio" id="star1half" name="rating" value="1.5" />
  30. <label class="half" for="star1half" title="Meh - 1.5 stars"></label>
  31. <input class="stars" type="radio" id="star1" name="rating" value="1" />
  32. <label class = "full" for="star1" title="Sucks big time - 1 star"></label>
  33. <input class="stars" type="radio" id="starhalf" name="rating" value="0.5" />
  34. <label class="half" for="starhalf" title="Sucks big time - 0.5 stars">
  35. </label>
  36. </fieldset>
  37.  
  38. <script>
  39. $(document).ready(function () {
  40. $("#seller_rate .stars").click(function () {
  41. $.post('db_rating.php',{rate:$(this).val()},function(d){
  42. if(d>0)
  43. {
  44. alert('You have already rated');
  45. }else{
  46. alert('Thanks For Rating');
  47. }
  48. });
  49. $(this).attr("checked");
  50. });
  51. });
  52.  
  53. <?php
  54. session_start();
  55.  
  56. //$seller_id = $_POST['seller_id'];
  57. $customer_id = $_SESSION['customer_id'];
  58. $servername = "localhost";
  59. $username = "root";
  60. $password = "";
  61. $dbname = "odsy";
  62.  
  63.  
  64. $conn = new mysqli($servername, $username, $password, $dbname);
  65. if ($conn->connect_error) {
  66. die("Unable to connect Server: " . $conn->connect_error);
  67. }
  68.  
  69. if (isset($_POST['rate']) && !empty($_POST['rate'])) {
  70.  
  71. $rate = $conn->real_escape_string($_POST['rate']);
  72. //$seller_id = $conn->real_escape_string($_POST['seller_id']);
  73. // check if user has already rated
  74. $sql = "SELECT `rating_id` FROM `rating` WHERE `customer_id`='" . $customer_id. "'";
  75. $result = $conn->query($sql);
  76. $row = $result->fetch_assoc();
  77. if ($result->num_rows > 0) {
  78. echo $row['rating_id'];
  79. } else {
  80.  
  81. $sql = "INSERT INTO `rating` (`seller_id`, `rate`, `customer_id`) VALUES ('" . $seller_id . "', '" . $rate . "', '" . $customer_id . "'); ";
  82. if (mysqli_query($conn, $sql)) {
  83. echo "0";
  84. }
  85. }
  86. }
  87. $conn->close();
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement