Jump to content

Recommended Posts

When my php code arrives at this line:

<?php
error_reporting(E_ALL);
include "dateheader.php"; 
(SNIPPED CODE)

header("Location: displayactive.php");

I get this error:Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\wb\dateheader.php:223

 

Here is dateheader.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en">

<head>
<title>title page</title>
<meta http-equiv="Content-Language" content="en-gb" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<style type="text/css">
etc. 

 

Which of these 3 files do I need to "fix" and how do I fix it?  If you need me to display the displayactive.php file let me know.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/146761-display-header-problem/
Share on other sites

I want to redirect to displayactive.php.

 

here is that file:

 

<?php require('secure.php'); 

include "connectdb.php"; ?>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Active Patients - Staff View</title>
<SCRIPT TYPE="text/javascript">
etc.

 

 

Both the dateheader.php and displayactive.php have headers, but those headers are needed, so do I need to delete all the info in the header of one of these files??

You would put your PHP code above the output, outputting php as you go is not a "Great" practice. It is far better to output after the processing or store the output in a string and echo that one statement out at the end.

 

A "bandaid" for this issue is ob_start but I would suggest fixing your code to flow properly.

you would put your PHP code above the output

 

WHICH code?  The code in displayactive.php or the file that has

header("Location: displayactive.php"); 

By "output" I assume you are referring to things inside a <head> </head>?

 

The file that has header ("location....) has a bunch of code before it that processes a form.  I want to re-direct to "displayactive.php", so do I need to put my whole entire php code before the header in displayactive?  That file is filled with php code mixed with html and I need that header info I think.

 

 

The file that has header ("location....) has a bunch of code before it that processes a form.   I want to re-direct to "displayactive.php", so do I need to put my whole entire php code before the header in displayactive?  That file is filled with php code mixed with html and I need that header info I think.

 

Mixing outputted html with php is not very good practice, especially if you need to output it before header calls. You should store output in a string and output it at the end of the script to avoid such issues.

 

Here the header is it needs to be before any data is output to the screen. So right after <?php and the <?php needs to be at the very top of the script.  You may have to re-work your code to get this to work, by either re-thinking the logic and figuring out a way to get that header redirect up top, or by storing output into a string then outputting at the end of the script.

Here is the very top of displayactive.php:

<?php require('secure.php'); 

include "connectdb.php"; ?>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Active Patients - Staff View</title>
<SCRIPT TYPE="text/javascript">
<!--

 

As you can see, it starts with <?php, so how do I change displayactive.php to prevent the error and still redirect to this page?

As you might have noticed, I am slow :-) given that we are up to message#5, I am not understanding *specifically* how to solve the problem, although I do understand your generic points about output.

 

Now if there is another way besides this problematic "header" command to redirect to another page by using PHP, I'm all ears!

"Mixing outputted html with php is not very good practice,"

 

Ok how would you do this without mixing:

 

<td>hello your name is <?php echo $row['name'];?></td>

 

So I (in my limited humble experience) take issue with not mixing html and php.  It's done all the time!

 

BUT I mainly want to figure out the current problem, so I hope I don't distract anyone with this message and then I don't get a solution - I just wanted to point this out :-)

Hi, I tried that but it didn't work.  Ok I'm going to show my whole code.  Where in this code do I change it so I can redirect to displayactive.php after this code is run??

<?php
error_reporting(E_ALL);
require('secure.php'); 

include "dateheader.php"; 
include "connectdb.php";


$newdate = date("Y-m-d", strtotime($_POST['rcf_date']));
echo "newdate:" . $newdate . "<br>";

$current_date = date ("m/d/y");


$query = "SELECT * FROM `icu` WHERE `id_incr` = '".$_POST['id_incr']."' ";
$result = mysql_fetch_array(mysql_query($query)) or die(mysql_error());

echo "<br> problist:" . $result['problist'];

$problist = $result['problist'];
if($problist != $_POST[problist]) {
$problist_date = date("Y-m-d H:i:s");
}
else {
$problist_date = $result['problist_date'];
}

$todo = $result['todo'];
if($todo != $_POST[todo]) {
$todo_date = date("Y-m-d H:i:s");
}
else {
$todo_date = $result['todo_date'];
}

$sql = "UPDATE icu SET
rm_loc = '" . mysql_real_escape_string($_POST['rm_loc']) . "',
patient = '" . mysql_real_escape_string($_POST['patient']) . "',
mrn = '" . mysql_real_escape_string($_POST['mrn']) . "',
age = '" . mysql_real_escape_string($_POST['age']) . "',
race = '" . mysql_real_escape_string($_POST['race']) . "',
gender = '" . mysql_real_escape_string($_POST['gender']) . "',
attg = '" . mysql_real_escape_string($_POST['attg']) . "',
cs_doc = '" . mysql_real_escape_string($_POST['cs_doc']) . "',
rcf_date = '" . $_POST['rcf_date'] . "',
dx = '" . mysql_real_escape_string($_POST['dx']) . "',
pmhx = '" . mysql_real_escape_string($_POST['pmhx']) . "',

code = '" . mysql_real_escape_string($_POST['code']) . "',
allergy = '" . mysql_real_escape_string($_POST['allergy']) . "',
todo = '" . mysql_real_escape_string($_POST['todo']) . "',
   	todo_date = '$todo_date',
   	problist_date = '$problist_date',
problist = '" . mysql_real_escape_string($_POST['problist']) . "',
comments = '" . mysql_real_escape_string($_POST['comments']) . "',
signoff_status = '" . $_POST['signoff_status'] . "',
rcf_date2 = '$newdate'


WHERE id_incr = ".$_POST['id_incr']."";
if (isset($sql) && !empty($sql)) {
echo "<!--" . $sql . "-->";
$result = mysql_query($sql) or die ("Invalid query: " . mysql_error());


?>
<p>
Done
<?php
}
header("Location: displayactive.php");

?>
[code]

The javascript way is a halfassed way imo.

 

<?php
error_reporting(E_ALL);
require('secure.php'); 

include "dateheader.php"; 
include "connectdb.php";


$newdate = date("Y-m-d", strtotime($_POST['rcf_date']));
// echo "newdate:" . $newdate . "<br>"; // commented out as it will cause header issues.

$current_date = date ("m/d/y");


$query = "SELECT * FROM `icu` WHERE `id_incr` = '".$_POST['id_incr']."' ";
$result = mysql_fetch_array(mysql_query($query)) or die(mysql_error());

// echo "<br> problist:" . $result['problist']; // commented out as it will cause header issues.

$problist = $result['problist'];
if($problist != $_POST[problist]) {
$problist_date = date("Y-m-d H:i:s");
}
else {
$problist_date = $result['problist_date'];
}

$todo = $result['todo'];
if($todo != $_POST[todo]) {
$todo_date = date("Y-m-d H:i:s");
}
else {
$todo_date = $result['todo_date'];
}

$sql = "UPDATE icu SET
   rm_loc = '" . mysql_real_escape_string($_POST['rm_loc']) . "',
   patient = '" . mysql_real_escape_string($_POST['patient']) . "',
   mrn = '" . mysql_real_escape_string($_POST['mrn']) . "',
   age = '" . mysql_real_escape_string($_POST['age']) . "',
   race = '" . mysql_real_escape_string($_POST['race']) . "',
   gender = '" . mysql_real_escape_string($_POST['gender']) . "',
   attg = '" . mysql_real_escape_string($_POST['attg']) . "',
   cs_doc = '" . mysql_real_escape_string($_POST['cs_doc']) . "',
   rcf_date = '" . $_POST['rcf_date'] . "',
   dx = '" . mysql_real_escape_string($_POST['dx']) . "',
   pmhx = '" . mysql_real_escape_string($_POST['pmhx']) . "',
   
   code = '" . mysql_real_escape_string($_POST['code']) . "',
   allergy = '" . mysql_real_escape_string($_POST['allergy']) . "',
   todo = '" . mysql_real_escape_string($_POST['todo']) . "',
      todo_date = '$todo_date',
      problist_date = '$problist_date',
   problist = '" . mysql_real_escape_string($_POST['problist']) . "',
   comments = '" . mysql_real_escape_string($_POST['comments']) . "',
   signoff_status = '" . $_POST['signoff_status'] . "',
   rcf_date2 = '$newdate'
   
   
   WHERE id_incr = ".$_POST['id_incr']."";
if (isset($sql) && !empty($sql)) {
//echo "<!--" . $sql . "-->";
$result = mysql_query($sql) or die ("Invalid query: " . mysql_error());

}
header("Location: displayactive.php");

?>

 

If you are redirecting you do not need to echo anything.  Echoing anything before a header command will cause it to not work.

 

You will also notice I removed the "done" why are you outputting done if you are just redirecting? Anyhow, I hope this helps you better to understand what is going on.

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.