基本上,我正在设置一个 mysql 准备的 select 语句,它使用 GET 从 url 中提取 id 我遇到的问题是类别和描述变量没有回显。我使用了一个非准备好的语句,它工作得很好。我尝试将变量输入到绑定结果中。$catid=intval($_GET['cid']);$stmt = mysqli_prepare($con, "Select id,CategoryName,Description,PostingDate,UpdationDate from tblcategory where Is_Active=1 and id='$catid'");$stmt->bind_param("ssi", $category,$description,$catid);$stmt->execute();$stmt->bind_result($category,$description,$catid);$stmt->fetch();echo $category;echo $description此代码的预期结果是从 url 中提取 catid 并选择所有列信息,然后能够回显描述和类别变量。
1 回答

长风秋雁
TA贡献1757条经验 获得超7个赞
就您的输出而言,您需要按照它们在查询中指定的顺序绑定结果集中的列。在你的情况下,你$catid
在错误的地方。这应该有效:
$stmt->bind_result($catid, $category, $description);
请注意,您缺少PostingDate
and 的绑定UpdationDate
,您可能也想添加它们,例如
$stmt->bind_result($catid, $category, $description, $postdate, $updatedate);
您的输入也有问题,您正在绑定查询中不存在的参数。由于您的查询只有一个输入,您应该用占位符替换它并绑定到它:
$stmt = mysqli_prepare($con, "Select id,CategoryName,Description,PostingDate,UpdationDate from tblcategory where Is_Active=1 and id=?"); $stmt->bind_param("i", $catid);
- 1 回答
- 0 关注
- 191 浏览
添加回答
举报
0/150
提交
取消