php项目中的未定义变量(Undefined variable in php project)
我是php和html的新手,我不断收到这个恼人的错误。 一切看起来都很好,但显然不是。 如果有人可以打扰向我解释或指出明显的,我会很感激。
该错误显示$ review处有一个未定义的变量
$stmt = $conn->prepare("SELECT rt FROM userhelp WHERE user_id != ? AND project_id = ?"); $stmt->bind_param("ii", $user_id, $project_id); $stmt->execute(); $stmt->bind_result($rt); while ($stmt->fetch()) { $reviews[] = $rt; } $stmt->close(); return $reviews; <------The error is right hereI'm fairly new to php and html and I keep getting this annoying error. Everything looks perfectly fine to me but it clearly isn't. If anyone could bother explaining to me or pointing out the obvious, I'd appreciate it.
The error reads that there is an undefined variable at $reviews
$stmt = $conn->prepare("SELECT rt FROM userhelp WHERE user_id != ? AND project_id = ?"); $stmt->bind_param("ii", $user_id, $project_id); $stmt->execute(); $stmt->bind_result($rt); while ($stmt->fetch()) { $reviews[] = $rt; } $stmt->close(); return $reviews; <------The error is right here最满意答案
你应该在while循环之前定义$reviews review。
$reviews = array(); while ($stmt->fetch()) { $reviews[] = $rt; } $stmt->close(); return $reviews;You should define $reviews before while loop.
$reviews = array(); while ($stmt->fetch()) { $reviews[] = $rt; } $stmt->close(); return $reviews;更多推荐
发布评论