HalfGod HalfGod - 7 months ago 6
SQL Question

Why is rowCount always 0, when i update my user table whit the following statment

So I want to update some user data in a mysql database, using a html form but the alerted number is always 0. But using the command in phpmyadmin it's working.
Maybe the prepare statment doing something wrong with my parameters?

function updateUser($newemail, $name, $email) {
$stmt = $this->db->prepare("update user set name=:name, email=:newemail where email=:email");
$stmt->bindValue(":newemail", $newemail, PDO::PARAM_STR );
$stmt->bindValue(":name", $name, PDO::PARAM_STR );
$stmt->bindValue(":email", $email, PDO::PARAM_STR );
$stmt->execute();

$x =$stmt->rowCount();
echo "<script>alert($x);</script>";
}


I am calling the function like this. so they new variables must be different:

if( (strcmp($newemail,$email) != 0) || (strcmp($newname,$name)!= 0) ){
$this->db->updateUser($newemail, $name, $email);
}

Answer

You're calling the function with the wrong name variable. You're giving the old name instead of the new name, so it's not changing the name.

if( (strcmp($newemail,$email) != 0) ||  (strcmp($newname,$name)!= 0) ){
    $this->db->updateUser($newemail, $newname, $email);
}
Comments