嗨,我不太确定我写的东西出了什么问题。一个朋友有模拟程序代码,但我的不起作用。非常感谢您的帮助。
if (isset($_GET['postID']))
{
$postID = $_GET['postID'];
$stmt = $mysqli->prepare("SELECT postTitle FROM Posts WHERE postID = ?");
$stmt->bind_param('i', $postID);
$stmt->execute();
$stmt->bind_result($postTitle);
echo $postTitle;
}
感谢
您尚未使用$stmt->fetch()
获取结果。尽管已将结果列绑定到$postTitle
,但除非从语句结果集中提取一行,否则没有可用的值。
// First, don't forget to establish your connection
$mysqli = new MySQLi($host, $user, $pass, $dbname);
if (isset($_GET['postID']))
{
$postID = $_GET['postID'];
$stmt = $mysqli->prepare("SELECT postTitle FROM Posts WHERE postID = ?");
$stmt->bind_param('i', $postID);
$stmt->execute();
$stmt->bind_result($postTitle);
// Use a while loop if multiple rows are expected,
// Otherwise, a single call to $stmt->fetch() will do.
while ($stmt->fetch()) {
echo $postTitle;
}
}