php 代码应该将我的数据库中的内容打印到模板中

标签 php html mysql templates mysqli

因此,我为我的网站布局制作了一个模板,用于每个页面,并且我想从数据库中获取内容。我的数据库中的内容只是文本,html 代码在我的模板中。

所有内容都存储在名为 tblPages 的数据库中,其中包含pagesID(用于选择右侧行)、inhoud(荷兰语内容,这是我页面上的主要内容)和 bubble(这是一个小语音框)。

现在,ID 应该在页面导航中找到的链接中发送,我使用这行代码执行此操作:

<php echo '<li><a href="index.php?id=3"><img src="../images/icons/home.png" alt="home">  </a> ?>

在本例中,它应该给出第 3 行的内容。

现在我收到的错误如下:

警告:mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]:变量数量与/Users/Caitlin/Pictures/School 2013-2014/GIP/Internet technieken 中准备好的语句中的参数数量不匹配/Caitlin_ArtMeetsArt/php/index.php 第 13 行

<php
require_once("../includes/dbconn.inc.php");
$inhoud = "";
$bubble = "";

if (!empty($_GET['id'])){
$id = $_GET['id'];
$qrySelectPage = "SELECT pagesID, inhoud, bubble
FROM tblPages";
if ($stmt = mysqli_prepare($dbconn, $qrySelectPage)) {
mysqli_stmt_bind_param($stmt, "s", $id); //LINE 13
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $pagesID, $inhoud, $bubble);
mysqli_stmt_fetch($stmt);
mysqli_stmt_close($stmt);
}
}
$content = "";
$paginatitel = "Home";
$content .= '<p class="content1">' . $inhoud . '</p>';
$bubble .= '<p class="bubble">' . $bubble . '</p>';
require_once("../includes/ama_template.inc.php");
?>

在我的模板中有以下代码

<html>
<body>
<?php echo $content; ?>
<?php echo $bubble; ?>
</body>
</html>

我省略了大部分 html 代码,因为它可能不相关。因为这是来 self 的数据库的唯一部分。

最佳答案

这是您的查询:

$qrySelectPage = "SELECT pagesID, inhoud, bubble FROM tblPages";

该查询中没有参数。您需要添加类似 WHERE id=? 的内容,然后将一个值绑定(bind)到该参数(?)。

关于php 代码应该将我的数据库中的内容打印到模板中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23527626/

相关文章:

php - 如何使用PHP修改xml文件

php - 创建没有框架依赖性的 RestFul API?

html - 推荐大型 HTML 数据表的解决方案?

javascript - 测试当某个元素失去焦点时哪个元素具有焦点

php - 在哪里检查 INSERT 语句的成功或失败?

php - 我如何在订单页面中调用我的mysqli?

php - mysql : fetch multidimensional arrays separated and sorted by date column

html - 我的 CSS 菜单隐藏在带 flash 的 iframe 后面

mysql - 什么会导致 Rails 创建重复记录?

MySql 根据多个条件提供重复计数