Problem with appending rating to a php variable

Sep 4, 2015 at 3:17 PM
Hello,

I've been trying to send the data from jquery to php in order to save rating to database.
However I am still unable to do this and even asking other people about the solution we couldn't find a satisfactory one.
Please tell me if this is how you'd do this.
 <form action="" name="review" id="review" method ="post">
  Rating: 
<input type="range" value="0" step="0.5" id="rating">
<div id="stars" class="rateit" onclick="" data-rateit-backingfld="#rating" data-rateit-resetable="false"  data-rateit-ispreset="true"
    data-rateit-min="0" data-rateit-max="10">
</div>
<input type="submit" name="submitcomment" id="submit"  value="Comment!">
</form>
Next is my jquery/ajax code:
$(document).ready(function () {
              $('#submit').click(function () {

                  var value = alert($('#stars').rateit('value'));

                  $.ajax({
                      url: 'itemreview.php',
                      type: "POST",
                      data: { value: value },
                      success: function (data) {
                          alert("Got it!"+ value);
                      }
                  });
              });
          });
And finally, php:
if(isset($_POST['submitcomment'])) {
    $userrating = $_POST['stars'];
               
               echo "Posted!";
               echo $userrating;
}
I just can't get the value from
$('#stars').rateit('value')
into my $userrating.

I've pasted my code with alert as it displays the value in the alert window. However I am unable to insert it into my $userrating.

Some people have suggested doing this:
data: {"value":value},
or
data: {value: value},
but nothing seems to work. Would you suggest me something that would work in this instance?

Thank you for your help
Coordinator
Sep 16, 2015 at 7:34 AM
Hi David,

It seems like your PHP code is expecting a field named "stars" , yet your AJAX submission sends a field named "value".

so change:
 data: { value: value },
to
 data: { stars: value },
Gidon