Well the issue my guess is with the query. I see what the problem is. The IS NOT NULL is the issue, because even if the entry is blank, it returns not null. Bad design on my part, sorry. Try this and see if it works.
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 != ''";
$result = @runquery($query);
$num = @mysql_numrows($result);
if($num > 0){
$flag = 1;
}