-4

到目前为止,这是我的 PHP 代码

    <?php
    $con=mysqli_connect("host","user","pass","db_name");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1");
    $row = mysql_fetch($result_set);
    $old_total = $row['total'];
    $new_total = $old_total + $_REQUEST['total'];
    mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1");
    mysqli_close($con);
    ?>

当我运行它时,它返回此错误: 调用未定义的函数 mysql_fetch()我在这里遗漏了什么吗?

4

4 回答 4

1

它应该mysqli_fetch代替mysql_fetch.

于 2013-03-08T04:52:35.727 回答
1

你必须使用

  $row = mysqli_fetch_assoc($result_set);

而不是

  $row = mysqli_fetch($result_set);

希望对你有用......

于 2013-03-08T04:54:42.273 回答
1

您应该在 mysqli_fecth_array/assoc 中使用 $row['points'] 而不是 $row['total']。

试试下面的代码:

<?php
$con=mysqli_connect("host","user","pass","db_name");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1");
$row = mysqli_fetch_assoc($result_set);
$old_total = $row['points'];
$new_total = $old_total + $_REQUEST['total'];
mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1");
mysqli_close($con);
?>
于 2013-03-08T04:55:04.707 回答
0

最终代码:

$result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1");
$row = mysqli_fetch_assoc($result_set);
$old_total = $row['points'];
$new_total = $old_total + $_REQUEST['total'];
mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1");
mysqli_close($con);
?>
于 2013-03-08T05:05:29.440 回答