简体   繁体   中英

PHP prepared statement error: Warning: mysqli_stmt::bind_param():

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;      }
        }           
  }
 ?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM