0

I have problem with jQuery raty + database. I want to add rate to my database. But it isn't work...

My js Code :

$(function() {
 $.fn.raty.defaults.path = 'images/img';
 //$('#default-demo').raty();
 $('#score-demo').raty({ cancel    : true,
        target    : '#hint',
        targetType: 'number',
        click : function(score){  
          $.post('rating.php',{score:score, userid:0 },
          function(data){
            alert(data+' Score = '+score);
            });}
    });
  });

My PHP code :

<?
session_start();
require_once("lib/class.Mysql.php");
$pol=new Mysql();

$rate=$_POST['score'];
$id='5';
$res = mysql_query("INSERT INTO `produkty_oceny` (id, id_produktu, ocena, ip) values ('','".$id."', '".$rate."','".$_SERVER['REMOTE_ADDR']."'");
//if(!$res) echo mysql_result($res, 0);

print_r("INSERT INTO `produkty_oceny` SET `id`='',id_produktu='".$id."' `ocena`='".$rate."', `ip`='".$_SERVER['REMOTE_ADDR']."'");
?>

Any ideas ?

Kubol
  • 136
  • 10
  • exactly what error you are getting? – Suresh Kamrushi Feb 05 '14 at 11:51
  • My mysql table 'produkty_oceny' is empty. If I change $rate=$_POST[score] to $rate=$_GET['score'] and I go to link ../rating.php?score=5 I didn't have any errors, but my mysql table is empty. – Kubol Feb 05 '14 at 11:54
  • Have you verified in Firebug or Chrome developer tools if the request has been sent properly? I think that problem could be the url that you are pasing to $.post. – Fran Muñoz Feb 05 '14 at 12:16
  • On Chrome I get something like this : This request has no response dataavailable – Kubol Feb 05 '14 at 12:35
  • Solved, with "mysql_query ("INSERT IGNORE INTO produkty_oceny (id, id_produktu, ocena, ip, data) values ('','".$id_produktu."', '".$rate."','".$_SERVER['REMOTE_ADDR']."', NOW())");" – Kubol Feb 05 '14 at 20:15

0 Answers0