php项目中的未定义变量(Undefined variable in php project)

编程入门 行业动态 更新时间:2024-10-26 10:39:10
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 here

I'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;

更多推荐

本文发布于:2023-07-30 00:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1320813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   未定义   项目   php   variable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!