Carefree4
Carefree4

Reputation: 23

Cant send data to database and redirect isn't working

When you hit the "Post" button it should send the data to the database and redirect you to ?success=true but it will not redirect you or send the data to the DB.

This is suppose to do the redirecting and function calling:

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

This is 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());
}

EDIT: You can log in to the off-topic page with the username: Test and password: Test123456789

Upvotes: 0

Views: 54

Answers (3)

Carefree4
Carefree4

Reputation: 23

I am so sorry... Because of the new background I was unable to see the error... In the DB something wasn't allowed to be null... So a quick fix and its working... Thank you all for the help!

Upvotes: 0

Rajeev Ranjan
Rajeev Ranjan

Reputation: 4142

put a return statement in function

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

Upvotes: 1

Nilesh
Nilesh

Reputation: 442

Try this if condition

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

Upvotes: 0

Related Questions