无法将数据发送到数据库,重定向无法正常工作

时间:2013-12-11 05:21:22

标签: php redirect

当您点击“发布”按钮时,它应该将数据发送到数据库并将您重定向到?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 and password:Test123456789

登录the off-topic page

3 个答案:

答案 0 :(得分:1)

在函数

中放置一个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;
}

答案 1 :(得分:0)

如果条件

,请尝试此操作
if (!empty($_POST['postBox']) && $_GET['success'] != 'true')

答案 2 :(得分:0)

我很抱歉......由于新的背景,我无法看到错误...在DB中,某些东西不允许为空...所以快速修复它的工作......谢谢大家帮忙!