-3

The Insert works perfectly as tested that without the header redirect. My problem is i'm using MYSQLI with Object oriented approach and still new to it. When i have the header redirect in there it tells me in the browser

"Warning: Cannot modify header information - headers already sent by (output started at /home/hawkwsco/public_html/admin/include/template/doc.inc.php:1) in /home/hawkwsco/public_html/admin/include/library/functions/process/process.inc.php on line 10"

My code is below:

<?php
require ($_SERVER['DOCUMENT_ROOT'].'/admin/include/config/config.inc.php');
$query = ("INSERT INTO page(pa_id, pa_page, pa_page_info) VALUES ('NULL', '{$_POST['page']}', '{$_POST['info']}')");
$mysqli->query($query);
header("Location: http://".$_SERVER['SERVER_NAME']."/admin/content.php");
exit;
?>

What am I doing wrong?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

2

Most likely the file you are including has some text in it being output (even a newline at the end of the file is enough) causing the output to start before the header can be sent. I usually make sure my includes do not have a ?> at the end to avoid this problem.

Alternatively, you can use output buffering (ob_start()) to avoid any output being sent until you are ready. ob_start() must be called before any output to be effective.

David
  • 618
  • 5
  • 9