Forum Moderators: coopster

Message Too Old, No Replies

header problems

         

Harry_C

4:30 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



I have looked all over, and have tried MANY things, but I still get this dreaded
Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\wwwroot\calendar\insert_events.php:38) in c:\inetpub\wwwroot\calendar\insert_events.php on line 39

This is line 39
header("Location:get_events.php?d=&m=&y=");

Please, if someone could tell me what the deal is, I would be most appreciated. The code below is on the top of the page, NO html is written before it, no in the included file either...

<?ob_start();?>
<?php require 'inc/db_connect.php';?>
<?

# this is processed when the form is submitted
# back on to this page (POST METHOD)
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

# double-up apostrophes
$EventTitle = str_replace("/","'",trim($_POST['_eventTitle']));
$EventDate = $_POST['_eventDate'];
$date_array = explode ("/", $EventDate);
$FormattedEventDate = $date_array[2] ."-" .$date_array[0] ."-" .$date_array[1];
$EventStartTime = $_POST['_eventStartHour'] . ':' . $_POST['_eventStartMinute'] . ' ' . $_POST['_eventStartAMPM'];
$EventEndTime = $_POST['_eventEndHour'] . ':' . $_POST['_eventEndMinute'] . ' ' . $_POST['_eventEndAMPM'];
$Location = str_replace("/","'",trim($_POST['_location']));
$Description = str_replace("/","'",trim($_POST['_description']));
$ContactName = str_replace("/","'",trim($_POST['_contactName']));
$ContactEmail = str_replace("/","'",trim($_POST['_contactEmail']));
$ContactPhone = str_replace("/","'",trim($_POST['_contactPhone']));

# setup SQL statement
$SQL = " INSERT INTO event ";
$SQL = $SQL . " (EventTitle, EventDate, EventStartTime, EventEndTime, Location, Description, ContactName, ContactEmail, ContactPhone) VALUES ";
$SQL = $SQL . " ('$EventTitle', '$FormattedEventDate', '$EventStartTime', '$EventEndTime', '$Location', '$Description', '$ContactName', '$ContactEmail', '$ContactPhone') ";

#execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);

# check for error
if (!$result)
{
echo("ERROR: " . mysql_error() . "\n$SQL\n");
}
else
{
mysql_close($cid);
ob_flush();
header("Location:get_events.php?d=&m=&y=");
}

#print ($SQL);

}
?>

jusdrum

5:17 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



ob_flush();
header("Location:get_events.php?d=&m=&y=");

The reason you are having this problem is because you are calling ob_flush(), then doing a redirect. ob_flush() sends the buffer to the browser, and once you send data to the browser, you can't use a redirect (or set cookies, or set session variables, for that matter). It's just the way PHP works.

Hope this helps!

Harry_C

5:19 pm on Mar 3, 2005 (gmt 0)

10+ Year Member



that was it...thank you very much...I appreciate it

Harry C

coopster

6:23 pm on Mar 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and welcome to WebmasterWorld, Harry_C.

ob_flush() [php.net]