Jump to content
Larry Ullman's Book Forums

Why This Update Prepared Statement Is Not Working?

Recommended Posts

I have following update statement in one of the script, and it is not working. I tried to debug as much as I can without success. What can be the problem?


$rating = 4;


$q = "UPDATE user_book_trn SET book_rating = ? WHERE user_id = 1 AND member_id=24 AND book_id=120";

$r = mysqli_prepare($dbc, $q) or trigger_error("Query: $q\n<br />" . mysqli_error($dbc));

mysqli_bind_param($r, 'i', $br);


$br = (int) $rating;

//echo "\n rating : " . $br;


if(mysqli_stmt_affected_rows($r)==1) {

echo "Thanks for submitting your rating for the book. We appreciate it!";

} else {

echo "error";

echo '<p>' . mysqli_stmt_error($r) . '</p>';



The query runs OK in phpmyAdmin with the given values and also for other values in tables. But this script always prints "error" message, but never shows any mysqli_stmt_error.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...