运行以下代码时出现此错误:
PHP致命错误:未捕获错误:在chk_discount.php中调用未定义函数mysqli_result():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. ";
}
}
?>
我应该如何编辑代码?
答案 0 :(得分:0)
mysqli_result()
确实不是你在这里寻找的,这在the docs中有所暗示。它存在于PHP 7中。
根据您的代码,您可能正在寻找mysqli_fetch_object()
或mysqli_fetch_row()
答案 1 :(得分:0)
根据doc, mysqli_result 是一个类,这就是为什么你有一个带有未定义函数的PHP致命错误。
我建议您尝试使用 mysqli_result :: fetch_assoc 将结果提取到关联数组中