如何在javaScript中刷新页面后更新数据库中表的星级速率? [重复]

I want give the opportunity to the user to change the rating value of a product, but it is not working after refreshing the page. For example, when he goes to a new product that he did not rate, he can change the rating value again and again before refreshing the page. But after refreshing the page he can change the rating value of the same product, but the alert for the "ratingValue2" is not working and the database is not updating.

Here is my PHP code.

$jsqla3 = mysql_query("select * from user_star_rate where product_id='$product_id' and email='$visit_email'") or die(mysql_error());
$jfeta3 = mysql_fetch_assoc($jsqla3);

if($jfeta3 != null) {
  $ratea = $jfeta3['rate_value'];
} 

Here is my HTML code.

<input class="rating form-control input-star-rate" id="<?php echo $rateid; ?>" name="rating" value="<?php echo $ratea; ?>" data-min="0" data-max="5" data-step="0.3" data-size="xs" style="display: none; text-align: center;"/>

Here is my javaScript code.

$(function(){
 $(document).ready(function(e) {
   var $stars = $('.input-star-rate');

   $stars.bind('change', function() {
      var $this = $(this); 
      var ratingValue = $this.val();
      var ratingValue2 = parseFloat(ratingValue);
      alert(ratingValue2);
   });
 });
});
</div>

At first you should remove the document.ready() as you have already used its shorthand.

And for your problem on refreshing the page you are not getting the updated rate then you need to update the database on changing the star rating by using $.ajax() something like,

$(function(){
    var $stars = $('.input-star-rate');

    $stars.bind('change', function() {
      var $this = $(this); 
      var ratingValue = $this.val();
      var ratingValue2 = parseFloat(ratingValue);
      alert(ratingValue2);
      $.ajax({
         url:'update_user_rate.php',data:{rate:ratingValue},
         success:function(data){
             alert(data);// you can apply check for success or error
         }
      });
    });
});

Also in the update_user_rate.php page you need to use query to update the database, so that you will get the updated user rate next time when you refresh the page.