Well removing the duplicate wouldn't do anything different. The error your getting has nothing to do with the username thing, it's just I used the same flag so when there's an error for either, it shows the same error. Try one last one.
PHP Code:
$ip = $_SERVER['REMOTE_ADDR'];
$ip = preg_replace("/[^a-zA-Z0-9@._-]/", "", $ip);
$ip = secure($ip);
$query = "SELECT * FROM ".$prefix."vote_voters WHERE ip = '$ip' AND username != 'Visitor'";
$result = @runquery($query);
$num = @mysql_numrows($result);
if($num > 0){
$flag = 1;
}