Reputation: 6355
I'm learning to use prepared statements to select all my data from the table in my database however i am getting this error
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match
number of parameters in prepared statement in
/Applications/XAMPP/xamppfiles/htdocs/contenteditable/classes/class.Insert.inc on
line 13
Perhaps I'm not using the prepared statements in the right way I'm not sure, I have used prepared statements before so hopefully somebody could tell me where Im going wrong or if anyone has a working example that would be helpful.
This is my code:
index.php
<div id="maincontent" contenteditable="true">
<?php
//get data from database.
require("classes/class.Insert.inc");
$insert = new Insert();
$insert->read();
?>
<button id="save">Save</button>
<input type="button" id="clear" value="Clear changes" />
</div>
classes/class.Insert.php
<?php
include("connect/class.Database.inc");
class Insert extends Database {
public $firstname;
public $content;
public function read(){
$stmt = $this->mysqli->prepare('SELECT * FROM datadump');
$stmt->bind_param('s', $content);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo $content; }
}
}
?>
Upvotes: 0
Views: 765
Reputation: 437376
bind_param
binds parameters for your query, which has zero placeholders. This causes PHP to complain.
You probably meant to use bind_result
instead, which is the way to export result set data into variables.
Upvotes: 1