Error in mysqli

hi guys

i get an error in this code (comment in the code):

if (checkBd ($sql, $db, $valor, $codePass)){

    ($sql = $db->prepare("UPDATE users SET activation = ? WHERE activationLink=?"));

    $valor="1";
    $sql->bind_param('is', $valor, $codePass);

    $sql->execute();

    $sql->bind_result($valor, $codePass); //Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement 

    if ($sql->fetch()) {
        header("location: index.php");
        return true;
    }
    else {
        echo "no";
        return false;
    }
$sql->close();
$db->close();
}

what is the possible problem in the script? an another question, is this way correct to update a boolean?

thanks

Hi

I am not 100% sure, my suggestion is going solve your issue…

But First you are trying to update column with (update query) using bind_param. Which is going working fine, i guess.
And then you are trying to fetch record using bind_result on update query and this line is not going to work as update query is not returning any record set.

Any ways bind_result works on number of column return as a result set of query. Update query is going to return true or false so instead of trying bind_result go for fetch() function directly.

Let me know if it works.

Cheers

thanks for your answer. If i use fetch() the code doesn’t work, then I took it.

Now works well

my final code is:


if (checkBd ($sql, $db, $codePass)){

	$valor=1;
	($sql = $db->prepare("UPDATE users SET activation=? WHERE activationLink=?"));

	$sql->bind_param('is', $valor, $codePass);

	$sql->execute();
	header("location: index.php");
	return true;
}
else {
	echo "no";
	return false;
}
$sql->close();
$db->close();


thanks!