无法将数据发送到数据库并重定向是';t工作


Cant send data to database and redirect isn't working

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

这是假设做重定向和函数调用:

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 登录主题外页面

在函数中放入一条返回语句

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

如果条件为,请尝试此操作

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

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