Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.