I'm using rateit rating plugin for my website (https://rateit.codeplex.com/). I'm trying to insert the value that a user selects into my database however every time I do this value 0 is inserted. Here is my code (PHP first):
session_start();
$username = $_SESSION['username'];
if(isset($_SESSION['username'])) {
$username = $_SESSION['username'];
}
else {
header('Location: login.php');
}
$itemid = $_GET['id'];
(HTML):
<div id="itemreview">
<form action="" name="review" id="review" method ="post">
Skin Type: <select name="skintype">
<option selected="">Skin Type</option>
<option value ="Oily">Oily</option>
<option value ="Mixed">Mixed</option>
<option value ="Sensitive">Sensitive</option>
<option value ="Normal">Normal</option>
</select><br>
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>
<br>
<textarea name="review" id="review" cols ="50" rows="8"></textarea>
<input type="submit" name="submitcomment" id="submit" value="Comment!">
</form>
Here's my Jquery/Ajax:
<script>
$(document).ready(function () {
$('#submit').click(function () {
//Create a variable to hold the value entered by the user
var stars = $('#stars').rateit('value');
$.ajax({
url: 'itemreview.php',
type: "POST",
data: { "stars" : stars },
success: function (data) {
alert("Got it!"+ stars);
}
});
});
});
</script>
And here's my php:
<?php
//Insert review into database
if(isset($_POST['submitcomment'])) {
$skintype = $_POST['skintype'];
$userrating = $_POST['stars'];
$userreview = $_POST['review'];
$insertreview = mysql_query("INSERT INTO itemcomments (itemid, username, commentcontent, ranking, userskintype) VALUE('$itemid', '$username',
'$userreview', '$userranking', '$skintype')");
echo "Posted!";
echo $userrating;
}
?>
While I can get the value displayed with the alert("Got it!"+ stars);
I cannot get the correct value inserted into database when I click submit.
For example, I rate something for 7.5. After hitting submit I get the alert message "Go it!7.5" but in the database the value inserted is still 0. All other values ($skintype, $userreview, $itemid and $username) are inserted properly.
What might be the issue?
Thank you all for your help.