Please, am i doing anything wrong, every time it runs it updates the email even if it exists in the database.
$error = ''; $userid = 1; $rows = $db->query("SELECT user_login, user_email FROM users WHERE ID != :ID", array('ID' => $userid ) ); if($rows){ foreach ($rows as $row) { if( $row['user_login'] == $phoneno){ $error = "phone number already exists"; }elseif ($row['user_email'] == $email) { $error = "email address already exists"; } else{ $error = ''; } } } if( $error == '' ){ $result = $db->query("UPDATE users SET user_login = :user_login, user_email = :user_email WHERE ID = :user_id", array('user_login' => $phoneno, 'user_email' => $email, 'user_id' => $userid) ); if($result){ $messages = "Account updated"; }else{ $errors = "Update failed"; } }else{ $errors = $error; }