text: Q:
  
  mysql_num_rows(); and header(); gives redirect loop
  
  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";
      }
  
  ?>
  
  A:
  
  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";
      }
  }
  ?>
  
  