i am basicly trying to update user information with a dynamic query.Everything good but when i try to execute query its return always false.
function updateUser($username, $email, $pass){
$arr = [];
$values = [];
$params = [];
if(isset($username))
{
array_push($arr, "userName = :username");
array_push($values, $username);
array_push($params, ":username");
}
if(isset($email))
{
array_push($arr, "userEmail = :email");
array_push($values, $email);
array_push($params, ":email");
}
if(isset($pass))
{
array_push($arr, "userPassword = :pass");
array_push($values, $pass);
array_push($params, ":pass");
}
$sql = "UPDATE users SET " . implode(", ", $arr) . " WHERE userId = :uId";
$query = $db->prepare($sql);
foreach ($params as $key) {
foreach ($values as $value) {
$query->bindValue($key, $value, PDO::PARAM_STR);
}
}
$query->bindValue(":uId", $_SESSION["userId"]);
if($query->execute() && $query->rowCount() > 0)
return true;
else
return false // always false return
}
this is my array datas: