当前位置: 首页 > 知识库问答 >
问题:

PHP致命错误:未捕获错误:调用未定义的函数mysqli_result()[duplicate]

经和洽
2023-03-14

运行以下代码时会出现此错误:

PHP致命错误:未捕获错误:调用chk_discount中的未定义函数mysqli_result()。PHP:21

以下是完整的代码:

<?php
include 'client_config.php';
foreach($_GET as $key => $value) {
    $get[$key] = filter($value);
}
$total = base64_decode($_GET['total']);
echo calculate_discount($_GET['code'],$total);
function calculate_discount($code, $total) {
    global $con;
    if ($code && $total) {
        $now = time();
        list($discount_offer_on_totals) = mysqli_fetch_row(mysqli_query($con, "select discount_offer from orders_discounts")); 
        if ( $total < $discount_offer_on_totals ) {
        return "Order total must be ".$curr_symbol. ' '. $discount_offer_on_totals." or more to qualify for discount!";
        }
        // check if code is valid and return result
        $sql = @mysqli_query($con, "SELECT * FROM orders_discounts WHERE codex = '$code' AND expiry > $now AND status = 1 AND $total > discount_offer");
        if (@mysqli_num_rows($sql) == 0) {
            return "Invalid coupon code. Please try again.";
        } else {
            return mysqli_result($sql, 0, "percentage");
            exit();
        }
    } else {
        return "Invalid request! Please enter correct code. ";
    }
}
?>

我应该如何编辑代码?

共有2个答案

佴飞驰
2023-03-14

根据文档,mysqli_result是一个类,这就是为什么有一个未定义函数的PHP致命错误。

我建议您尝试使用mysqli_result::fetch_assoc将结果取到关联数组中

袁翰池
2023-03-14

mysqli_result()确实不是您在这里要找的东西,这在文档中有某种暗示。但它存在于PHP7中。

根据您的代码,您可能正在查找类似mysqli_fetch_object()mysqli_fetch_row()的内容

 类似资料: