Jump to content

redirects and error


jeff5656

Recommended Posts

I get this error :Warning: Cannot modify header information - headers already sent by (ou..."

 

Now I read that I get this error if there is any HTML prior to this command, but as you can see below, I don't have any HTML!  So how do I correctly redirect after the following code is run?

 



include "../connectdb.php";
$this_month=$_POST['which_month'];
$query = "UPDATE staffsched SET ";
$set = array();
foreach($_POST as $field => $value){
    $field = mysql_real_escape_string($field);
    $value = mysql_real_escape_string($value);
    $set[] = "`{$field}` = '{$value}'";

}


$query .= implode(", ",$set) . " WHERE `which_month` = '".$this_month."'";
mysql_query($query) or die(mysql_error());

header("Location: editcurrent.php");
?>

Link to comment
https://forums.phpfreaks.com/topic/133599-redirects-and-error/
Share on other sites

The error message tells you where the output is occurring that is preventing the header. The output can be anything and is not specifically just HTML. It can be a space, new-line, UTF-8 BOM, HTML...

 

Post the whole error message and the code is mentions if you want any specific help.

Link to comment
https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694957
Share on other sites

Sorry I see no spaces:  The very very first line of this code (called commit.php) is <?php:

 

<?php include "../connectdb.php";
$this_month=$_POST['which_month'];
$query = "UPDATE staffsched SET ";
$set = array();
foreach($_POST as $field => $value){
    $field = mysql_real_escape_string($field);
    $value = mysql_real_escape_string($value);
    $set[] = "`{$field}` = '{$value}'";

}


$query .= implode(", ",$set) . " WHERE `which_month` = '".$this_month."'";
mysql_query($query) or die(mysql_error());

header("Location: editcurrent.php");
?>

 

Here is the exact error message that someone requested:

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/f/jeffjn/html/connectdb.php:2) in /home/content/j/e/f/jeffjn/html/schedules/commit.php on line 16

Link to comment
https://forums.phpfreaks.com/topic/133599-redirects-and-error/#findComment-694993
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.