Pergunta

So I have made a template for the layout of my website that I use for every page and I want to get the content from my database. The content in my database is all just text and the html code is in my template.

All content is stored in the database named tblPages that contains pagesID (used to select the right row),inhoud (dutch for content, which is the main content on my page) and bubble (which is a little speech box).

Now the ID should be send in the link that is found in the navingation of the page, this I do with this line of code:

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

In this case it should give the content that is on row 3.

Now the error that I'm getting follows:

Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of variables doesn't match number of parameters in prepared statement in /Users/Caitlin/Pictures/School 2013-2014/GIP/Internet technieken/Caitlin_ArtMeetsArt/php/index.php on line 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");
?>

And in my template is the following code

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

I left out most of my html code since it's probably not relevant. Since this is the only part that comes from my database.

Foi útil?

Solução

Here's your query:

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

There are no parameters in that query. You need to add something like WHERE id=? and then bind a value to that parameter (the ?).

Outras dicas

Your query doesn't have any parameter markers in it (a parameter marker in this case is a question mark):

SELECT pagesID, inhoud, bubble FROM tblPages

It would work if it looked more like:

SELECT pagesID, inhoud, bubble FROM tblPages WHERE pagesID=?

The question mark is where the bound parameter will go.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top