0

I want to pass a variable to a page, but cannot modify header... is always in the way

if(isset($_POST['send']))
{
$sender = $_SESSION['Email'];
$receiver = $_POST['email'];
$message = $_POST['textmessages'];
$date = date("Y-m-d h:i:sa");

$q = 'INSERT INTO `tblmessage`(`id`,`sender_name`,`receiver_name`,`message_text`,`date_time`,`userid`)
       VALUES("","'.$sender.'","'.$receiver.'","'.$message.'","'.$date.'","'.$user_id.'")';
$r = mysqli_query($con, $q);

if($r)
{
          header("location.href='messages.php?user=".$receiver);
}   
else
{
    echo $q;
}

}

I tried passing the user to the page, but:

output started at C:\xampp\htdocs\MBPH(Beta)\messages.php:79) in `C:\xampp\htdocs\MBPH(Beta)\newmessage.php on line 38

always pops up, that line 38 is

'header("location.href='messages.php?user=".$receiver);'
user3783243
  • 5,368
  • 5
  • 22
  • 41
Ralph Arca
  • 15
  • 4

2 Answers2

0

You could add ob_end_flush() before your header() function. It will clear out the current output buffer and your header() should be sent.

Reference: ob_end_flush() documentation

Miranda
  • 60
  • 9
0

You can try this code

ob_start();
Your output here
ob_get_contents();
Sunil R
  • 1
  • 2