【发布时间】:2018-05-30 08:51:59
【问题描述】:
运行以下代码时出现此错误:
PHP 致命错误:未捕获的错误:调用 chk_discount.php:21 中未定义的函数 mysqli_result()
这是完整的代码:
<?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. ";
}
}
?>
我应该如何编辑代码?
【问题讨论】:
-
“我知道 mysqli_result() 在 PHP 7 中不存在”——你错了。它确实存在于 PHP 7 中。可能您只是没有安装扩展。安装它。
-
这有点令人困惑。我正在尝试使用此线程上的建议 stackoverflow.com/questions/34118031/… Aint 也可以工作
-
同意@Quentin。见这里:-prnt.sc/jog3jn。还有你在代码中使用这个函数的地方吗?我看不到
-
我建议你停止在代码中使用
@,这会覆盖其他错误。