Jump to content

[SOLVED] ??Cannot modify header information??


kidintraffic

Recommended Posts

I have a form that takes data from a form and puts it into a mysql database.  On the form I also have a image upload box, where the user browses for an image and then uploads.  If the user doesn't put a image to be uploaded or it's too big of a file they receive the message that I have to be displayed.  But I also receive this error

 

Warning: Cannot modify header information - headers already sent by (output started at /var/www/page.php:26) in /var/www/page.php on line 33

 

here is the ending code where I think the problem is

 

echo "<b><font color=red>No file uploaded.</font></b><BR>No file available or file too big to upload.";
} 


$query = "INSERT INTO table VALUES ('',"')";
mysql_query($query);

header("location:nextpage.php");

 

is there error coming up because the printing the error and then trying to redirect to another page?  How do I go about fixing this?

Link to comment
https://forums.phpfreaks.com/topic/49739-solved-cannot-modify-header-information/
Share on other sites

Or would I do something like this?

 

ob_start();
echo "<b><font color=red>No file uploaded.</font></b><BR>No file available or file too big to upload.";
} 


$query = "INSERT INTO table VALUES ('',"')";
mysql_query($query);

header("location:nextpage.php");

ob_end_flush();

 

Well, the problem is that you cannot modify headers after content is sent (cookies, headers etc).

 

The best way to work around this is to do all of your processing before header() calls, but you could also use ob_start() at the top of the page.

 

The thing I don't get is, why echo a message if you're about to redirect the page?

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.