Search code examples
phpmysqlmysqlibindparam

bind_param error in PHP: "number of variables doesnt match number of parameters"


I am well aware this question has been asked before and I am really sorry for asking again, but the others didn't answer it for my situation. I have no idea what could be wrong with this bind_param. Here is the code for my PHP:

<?php
$db = new mysqli("localhost", "HIDDEN", "HIDDEN", "HIDDEN");
if ($db->connect_error) {
   die("Sorry, there was a problem connecting to our database.");
}

$username = stripslashes(htmlspecialchars($_GET['username']));

$result = $db->prepare("SELECT * FROM messages");
$result->bind_param("s", $username);
$result->execute();

$result = $result->get_result();
while ($r = $result->fetch_row()) {
   echo $r[1];
   echo "\\";
   echo $r[2];
   echo "\n";
}

What could be wrong with this bind_param? Sorry to bother again and thanks for the help.


Solution

  • That's because you are trying to bind variable s here $result->bind_param("s", $username);.

    Problem is that you are not using it in your query.