kidintraffic Posted May 3, 2007 Share Posted May 3, 2007 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? Quote Link to comment Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment Share on other sites More sharing options...
kidintraffic Posted May 3, 2007 Author Share Posted May 3, 2007 So do I just take out the error output and put that below the header()? Quote Link to comment Share on other sites More sharing options...
kidintraffic Posted May 3, 2007 Author Share Posted May 3, 2007 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(); Quote Link to comment Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 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? Quote Link to comment Share on other sites More sharing options...
kidintraffic Posted May 3, 2007 Author Share Posted May 3, 2007 Well I was trying to display a message only if an error occurred with the file upload. and if not it should redirect to a page. But just typing that out, I think I figured out my own problem. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.