【问题标题】:PHP header not redirecting, but there is no output in front of itPHP标头没有重定向,但它前面没有输出
【发布时间】:2012-07-02 21:33:56
【问题描述】:

我有一个 php 页面,允许用户输入一些数据,并尝试将它们放入数据库。但是,我的标题不起作用。它运行查询,但在标题处停止,并显示一个空白页。有人可以帮帮我吗?

<?php   
if(isset($_POST['submit'])) {
    $user_id = $_POST['user_id'];
    $user_vcode = $_POST['user_vcode'];
    $send_data = true;

    if(empty($user_id) || empty($user_vcode)){
        $send_data = false;
    }

    if($send_data){
        require("../../db.php");
        $account_id = $_COOKIE['account_id'];
        $query = "INSERT INTO api (key_id, key_vcode, owner_id) VALUES ('$user_id', '$user_vcode', '$account_id')";
        $result = mysqli_query($dbc, $query) or die("Failed querying database");
        mysqli_close($dbc);
        header("Location: http://www.google.com");
        die();
    }
}
?>

【问题讨论】:

  • ../../db.php 是否有任何尾随空格?您是否为错误报告设置了E_ALL
  • 啊,好吧。我又一次犯了错误。这解决了一切。谢谢!

标签: php mysql forms redirect header


【解决方案1】:

文件末尾的空格可能会很痛苦。检查最后一个 ?&gt; 标记后是否有任何尾随回车或空格。

【讨论】:

  • 因为这个原因,我通常会省略结束语?>。
  • 恕我直言,布伦特,这有点懒惰。看看这场长期争论:stackoverflow.com/questions/4410704/php-closing-tag
  • 问题出在 require() 上。它有一个完整的 html 文档,而不仅仅是 php。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多