php - mysql_num_rows();和标题();给出重定向循环

标签 php mysql

我在使用 header() 时遇到重定向循环错误;在 mysql_num_rows() 之后;如果我替换 header(); with echo 没有重定向循环错误。

<?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";
    }

?>

最佳答案

试试这个。如果不起作用请告诉我

<?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";
    }
}
?>

关于php - mysql_num_rows();和标题();给出重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10577644/

相关文章:

php - 当客户在结帐期间注册时,结账和客户注册失败

PHPExcel 无法打开保存的文件

c# - 如何在 Entity Framework 中有条件地生成DatabaseGenelated GUID

c# - 检索最后插入的记录

php - 这段代码的事务和回滚

php - mysqli_fetch_array 只显示第一个结果

php mysql 在同一个表中获取具有父 ID 的记录

php - 在更新值之前获取 mysql 表中值的差异

php - 未知查询 : call update_oai()

sql - 如何以及何时更新 MySQL 索引?