VentrixCode
VentrixCode

Reputation: 5

mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement on line 64

I wanted to make a login script for my program but its not working. The error is on the bind_param. Can you please explain why it's not working and teach me how to do it right?

Code:

<?php
$username = $_GET['username'];
$key = $_GET['key'];
$hwid = $_GET['hwid'];


$istKorrekt = istKorrekterSchluessel($username, $key, $hwid);
if($istKorrekt) {
    echo 'true';
} else {
    echo 'false';
}

mysqlTrennen();


function mysqlVerbinden() {
    global $mysqlVerbindung;
$mysqlHost = "localhost";
$mysqlBenutzer = "ts3botauth";
$mysqlPasswort = "nope";
$mysqlDatenbank = "ts3botauth";
$mysqlTabelle = "ts3botauth";
$mysqlVerbindung = new mysqli($mysqlHost, $mysqlBenutzer, $mysqlPasswort, $mysqlDatenbank);

    if($mysqlVerbindung->connect_errno)
        return false;

    return true;
}

function mysqlTrennen() {
    global $mysqlVerbindung;

    $mysqlVerbindung->close();
}

function istKorrekterSchluessel($username, $key , $hwid) {
    global $mysqlVerbindung;
    $mysqlTabelle = "ts3botauth";
    $stmtPruefung = $mysqlVerbindung->prepare("SELECT EXISTS(SELECT * FROM " . $mysqlTabelle . " WHERE `Key`=? AND `Username`=? AND `HWID`=?) AS schluesselKorrekt");

    if(!$stmtPruefung) {
        return false;}  
   $stmtPruefung->bind_param("s",$username);
    $stmtPruefung->bind_param("s", $key);
    $stmtPruefung->bind_param("s", $hwid);

    $stmtPruefung->execute();

    $stmtPruefung->bind_result($schluesselKorrekt);

    $stmtPruefung->fetch();

    return ($schluesselKorrekt == 1);
}

?>

Upvotes: 0

Views: 325

Answers (1)

Don&#39;t Panic
Don&#39;t Panic

Reputation: 41820

That's not how bind_param works in mysqli. Maybe you were thinking of PDO? In mysqli you have to bind them all at once with one statement.

$stmtPruefung->bind_param("sss",$username, $key, $hwid);

Line 64 will be $stmtPruefung->bind_param("s",$username);, and you're getting that "Number of variables doesn't match" error because it's expecting all three and you're giving it one.

Upvotes: 2

Related Questions