插入给定评分的评分和通话平均值

时间:2016-09-22 05:51:05

标签: php mysql joomla3.0

我正在尝试在数据库中插入评级并从数据库中调用给定评级的平均值

<?PHP
$connection = mysqli_connect("localhost", "akdnaklnd", "lfnlfns","faknfns");
$game = $_POST['game'];
$post_rating = $_POST['rating'];
$find_data = mysqli_query( "SELECT * FROM rates WHERE game='$game'");
while($row = mysqli_fetch_assoc($find_data)){
    $id=$row['id'];
    $current_rating = $row['rating'];
    $current_hits=$row['hits'];
}
$new_hits = $current_hits + 1;
$update_hits= mysqli_query("UPDATE rates SET hits = '$new_hits' WHERE id='$id'");                                  
$pre_rating= $current_rating + $post_rating;
$new_rating = $pre_rating / $new_hits;
$update_rating = mysqli_query("UPDATE rates SET rating ='$new_rating' WHERE     id='$id'");
header("location : average.php");
?>

3 个答案:

答案 0 :(得分:0)

$connection param添加到mysqli_query,如下所示:

$find_data = mysqli_query($connection, "SELECT * FROM rates WHERE game='$game'");

在&#34; location&#34;之后删除空格符号结肠前:header("location: average.php");

答案 1 :(得分:0)

尝试通过从代码中删除所有MySQL内容来调试它,并保持重定向代码没有空间,即。

header("location:average.php");

如果有效,则MySQL查询必定存在错误。尝试在执行每个MySQL查询操作后添加错误检查。希望这能帮助您在重定向语句之前找到执行终止的断点。

答案 2 :(得分:0)

首先,您无需选择可直接编写更新查询的数据,如下所示。 请确保您传递变量而不是字符串,以便更好地练习使用双引号和单引号以及dott。

最重要的传递连接变量。

$update_hits= mysqli_query($connection,"UPDATE rates SET hits = hits+1 WHERE id='".$id."'");

尝试echo $ update_hits如果它给出一个然后查询成功,否则有问题。

为此您可以使用错误日志

    if (!$result) {
        $errorQuery = $update_hits;
        throw new Exception(mysqli_error($connection));
       $errorMessage =  mysqli_real_escape_string($connection,$e->getMessage());
       echo $errorMessage;
       exit();
    }
    else{
       echo "Success";
    }