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
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();

 

Link to comment
Share on other sites

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?

Link to comment
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.