Php 无法将数据发送到数据库并重定向isn';行不通

Php 无法将数据发送到数据库并重定向isn';行不通,php,redirect,Php,Redirect,当您点击“Post”按钮时,它应该将数据发送到数据库并将您重定向到?success=true,但它不会将您重定向或将数据发送到数据库 这将执行重定向和函数调用: if (empty($_POST['postBox']) === false && $_GET['success'] != true){ sendPost(); header("LOCATION: /offtopic.php?success=true"); exit(); } 这是sendPos

当您点击“Post”按钮时,它应该将数据发送到数据库并将您重定向到?success=true,但它不会将您重定向或将数据发送到数据库

这将执行重定向和函数调用:

if (empty($_POST['postBox']) === false && $_GET['success'] != true){
    sendPost();
    header("LOCATION: /offtopic.php?success=true");
    exit();
}
这是sendPost:

function sendPost()
{
    $postBox = '\'' . htmlentities(mysql_real_escape_string($_POST['postBox'])) . '\'';
    $user_id = $_SESSION['user_id'];
    mysql_query("INSERT INTO `offtopicposts` (user_id, post, reported) VALUES ($user_id, $postBox, 0)") or die(mysql_error());
}
编辑: 您可以使用用户名:Test和密码:Test123456789登录到。如果条件允许,请尝试此操作

if (!empty($_POST['postBox']) && $_GET['success'] != 'true')

将return语句放入函数中

function sendPost()
{
    $postBox = '\'' . htmlentities(mysql_real_escape_string($_POST['postBox'])) . '\'';
    $user_id = $_SESSION['user_id'];
    mysql_query("INSERT INTO `offtopicposts` (user_id, post, reported) VALUES ($user_id, $postBox, 0)") or die(mysql_error());
   return;
}

我很抱歉。。。由于新的背景,我无法看到错误。。。在数据库中,某些内容不允许为空。。。所以一个快速修复和它的工作。。。谢谢大家的帮助

它的作用是什么?此外,是否打开了错误报告?错误报告已打开,它不会重定向或向DB发送任何内容,如果您转到bluewatercode.com/offtopic.php并使用用户名登录,您可以看到它没有做什么:测试通过:Test123456789只是为了好玩,发布
print\r()
可以设置
$\u POST
$\u GET
的值吗?设置了
$\u POST['postBox']
,如果if语句不存在,我可以调用它。不,同样的事情。。。不会发送到数据库或重定向。。。数据库工作正常,我可以登录,一切正常。没有给我任何错误或任何东西…只是尝试用if(1)进行更改,这会成功,然后你的if条件出现问题。我尝试了你的代码,对我来说工作正常,只需检查服务器错误日志或访问日志中是否有任何错误或警告,这就是我现在看到的,“已删除MaxRedirects选项以支持全局LimitInternalRecursion指令将被忽略”@Carefree4在调用
sendPost()后回显某个内容;
如果有控件,则标头()有问题函数。它在重定向前后都有回声。@Carefree4您是否用一些已知的域(如
http://google.com
在标题()中。