Felito
March 23, 2011, 12:56am
1
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
tejash
March 23, 2011, 1:51am
2
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
Felito
March 23, 2011, 1:58am
3
tejash:
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!