mysql_num_rows(); 和header(); 给出重定向循环

I'm getting a redirect loop error for using header(); after mysql_num_rows(); if I replace header(); with echo doesn't have a redirect loop error.

<?php

  require("includes/inc.php");

$id = trim(sanitize($_GET['id'])); //Receives the id of the file from the url

$fileid = mysql_query("SELECT * FROM files WHERE fileid = '$id'");
    if (mysql_num_rows($fileid) != 1) {
        header('Location: download.php?error=invalid_file');
    } else {
        echo "File Exist";
    }

?>

Try this. Let me know if doesn't works

<?php

  require("includes/inc.php");

$id = trim(sanitize($_GET['id'])); //Receives the id of the file from the url

if($id)
{
    $fileid = mysql_query("SELECT * FROM files WHERE fileid = '$id'");
    if (mysql_num_rows($fileid) != 1) {
        header('Location: download.php?error=invalid_file');
    } else {
        echo "File Exist";
    }
}
?>

There's not enough information here. What's the name of the file above? And what is the PHP code in download.php? Are there any redirects in includes/inc.php?

Of course you don't get an error if you remove the header() call -- it's the header('Location: download.php...') that does the redirect.