= 1 && $rating <= 5) { if (@mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT id FROM ratings WHERE IP='".$ip."' AND rating_id='".$game."'")) || isset($_COOKIE['has_voted_'.$game])) { return 'already_voted'; } setcookie('has_voted_'.$game, $game, $expire, '/', $domain, false); mysqli_query($mysqli, "INSERT INTO ratings (rating_id,rating_num,IP) VALUES ('".$game."','".$rating."','".$ip."')"); mysqli_query($mysqli, "UPDATE games SET voted_".$rating." = (voted_".$rating." + 1) WHERE id='".$game."'"); if ($method == 'POST') { $data = mysqli_fetch_assoc(mysqli_query($mysqli, " SELECT ((voted_1 + (voted_2 * 2) + (voted_3 * 3) + (voted_4 * 4) + (voted_5 * 5)) / (voted_1 + voted_2 + voted_3 + voted_4 + voted_5)) AS rating FROM games WHERE id='".$game."' ")); $perc = $data['rating'] * 20; return round($perc, 2); } if ($method == 'GET') { header("Location:".$_SERVER['HTTP_REFERER'].""); die; } } else if ($method == 'GET') { return 'You cannot rate this more than 5 or less than 1 back'; } } if ($_POST) { echo process($mysqli, 'POST', $ip, $expire, $domain); } else if ($_GET) { echo process($mysqli, 'GET', $ip, $expire, $domain); } ?>