How to insert rateit rating value into database ?

Dec 15, 2013 at 9:22 AM
i am trying to insert rating value into my database , but i am not able to insert the value of rating into database .
Jan 25, 2014 at 5:55 PM
Edited Jan 25, 2014 at 5:56 PM
Hi neildhakal,

Well, after do a rate, you need to call a PHP file with some parameters to write on your database.

Here the sample code:

JS FILE
$('.ratingContainer .rateit')
.rateit({ max:5, step: 1 , min:0 })
.bind('rated reset', function (e) 
{

     var ri = $(this);
     var voteValue = ri.rateit('value');
     var localID = ri.data('productid');
     var localName = ri.data('productname');

     ri.rateit('readonly', false);

     $.ajax({
         url: 'rate.php',
         data: { localID: localID, voteValue: voteValue, localName: localName },
         type: 'POST',
         success: function (data) {
            $('#responseRate'+localID).show();
         }               
     });
});
RATE.PHP file:
<?php include 'db.php'; ?>
<?php
if(!empty($_POST['localID']) && !empty($_POST['voteValue']) && !empty($_POST['localName'])){

    $localID = $_POST['localID'];
    $voteValue = $_POST['voteValue'];
    $localName = $_POST['localName'];

    $insert = "insert into vote (voteValue,localID,localName) values ('{$voteValue}','{$localID}','{$localName}')";
    mysql_query("SET NAMES utf8");
    $result = mysql_query($insert);

    if($result){
        echo "success"; 
    } else {
        echo "error";
    }

} else {
    echo "error";   
}

exit;
?>