php - No update in Boolean field

Asked

Viewed 124 times

1

I am trying to update the user data, but the active field is not updated.

I have tried several changes and also change the variable value $active of boolean for int, but without success.

Another behavior I noticed is when I do not make any changes in the fields and have the update, the $stmt->affected_rows returns 0, this is normal?

public function user_update($user_id, $name, $email, $active)
{
    $stmt = $this->conn->prepare("UPDATE users SET user_name = ?, user_email = ?, user_active = ? WHERE user_id = ?");
    $stmt->bind_param("ssbi", $name, $email, $active, $user_id);
    $stmt->execute();
    $num_affected_rows = $stmt->affected_rows;
    $stmt->close();
    return $num_affected_rows > 0;
}

The version of php is 5.6.22, and the base is MySQL

  • what comes in echo $active?

  • Hello, do the following tries to make a condition, sometimes the boolean picks up T or F, or in some cases picks up 0 or 1 , better insert in the manual seat and see what saves there

  • @Andrébaill comes true or false

1 answer

2


b is for blob and non-Boolean fields/values, change the b for i if you are passing 0 or 1. Or switch to s for values t or f

$stmt->bind_param("ssii", $name, $email, $active, $user_id);
  • I already switched to i and it didn’t work, I’ll try to put s

  • @adelmo00 picks up the error return with, $stmt->execute() or die(mysqli_error($this->conn));

  • I switched to you and it worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.