473,568 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Headers already sent problem online, but not offline

I have a problem where when I run the PHP code offline, there are no errors
produced and the code runs as expected. However when I uploaded the same
script and run it, it says the headers have already been sent.

The script is for a "downloader " type script, where the user clicks on a
file link (to the PHP script) using $_GET to pass the selected files ID to
the script, and the information about the file is read out from a database,
also updating a field in the database on how many times a file has been
accessed, and then produces the browsers "save as" dialog box according to
which file type was accessed.

Below is the code, if anyone can help how to sort this problem out. I put
line numbers in to show where the errors occur, along with the error
report.

Thanks

Dariusz
// Connect (log on) to the database
$connection = @mysql_connect( "localhost" , "xxx", "xxx");

mysql_select_db ($DatabaseName) ;

// Display database entries
$sql = mysql_query("SE LECT * FROM $TableName WHERE f_id='$FileID'" );

$FileInfo = mysql_fetch_row ($sql); <-- Line 22
// Read from the array the files URL
$FileURL = 'http://'.$FileInfo[0];
// Read from the array the files name
$FileName = $FileInfo[1];
// Read file size from the database
// Problem using the built-in function to read file size of stated file
$FileSize = $FileInfo[2];
// Write code for number of accesses a file has had
$FileAccessed = $FileInfo[3];

$FileAccessed = $FileAccessed + 1;

$sql = ("UPDATE $TableName SET f_accessed=$Fil eAccessed WHERE
f_id='$FileID'" );
$result = @mysql_query($s ql, $connection);

$FileType = substr($FileID, 0, 3);

MYSQL_CLOSE();

//Screensavers
if ($FileType == 'scr')
{
// We'll be outputting a screensaver
header('Content-type: application/octet-stream'); <-- Line 46
// Filename
header("Content-Disposition: attachment; filename=$FileN ame;"); <-- Line48
header('Content-Transfer-Encoding: binary'); <-- Line 49
// Calculate file size
header('Content-Length: '.$FileSize); <-- Line 51
// The location of the file
readfile($FileU RL); <-- Line 53
}
Errors:
Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result
resource in /home/php/downloader.php on line 22

Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
46

Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
48

Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
49

Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
51

Warning: readfile(http://): failed to open stream: Success in
/home/php/downloader.php on line 53
Jul 17 '05 #1
2 2584
In article <mw************ *********@wards .force9.net>,
ng@lycaus.plusY OURSHIT.com (Dariusz) wrote:
Below is the code, if anyone can help how to sort this problem out. I put
line numbers in to show where the errors occur, along with the error
report.
[...]
Errors:
Warning: mysql_fetch_row (): supplied argument is not a valid MySQL result
resource in /home/php/downloader.php on line 22

Warning: Cannot modify header information - headers already sent by (output
started at /home/php/downloader.php: 22) in /home/php/downloader.php on line
46


The 'headers already sent' error is because of the first error (the
mysql_fetch_row () one on line 22). The headers can't be sent because the
first error message got in the way.

Your mysql_query:

$sql = mysql_query("SE LECT * FROM $TableName WHERE f_id='$FileID'" );

failed for some reason.

JP

--
Sorry, <de*****@cauce. org> is een "spam trap".
E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.
Jul 17 '05 #2
ng@lycaus.plusY OURSHIT.com (Dariusz) wrote in
news:mw******** *************@w ards.force9.net :
I have a problem where when I run the PHP code offline, there are no
errors produced and the code runs as expected. However when I
uploaded the same script and run it, it says the headers have already
been sent.
That's a side effect of your primary problem, namely that your SQL query is
failing. That results in an error message when you try to use the result
of the query, and that error message is being output as text, which means
that PHP has to first send out a header and then the error message, which
means that you can't send out any futher headers.
// Connect (log on) to the database
$connection = @mysql_connect( "localhost" , "xxx", "xxx");

mysql_select_db ($DatabaseName) ;

// Display database entries
$sql = mysql_query("SE LECT * FROM $TableName WHERE f_id='$FileID'" );
All three preceding statements need error checking; you're just blindly
assuming that they're all going to be successful.

$FileInfo = mysql_fetch_row ($sql); <-- Line 22


This will generate an error message if any of the preceding operations
failed.

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3163
by: Phyzlo | last post by:
Hello, I've recently started learning PHP and have a question. I tried running below script which can be found at http://se2.php.net/manual/sv/function.setcookie.php but I keep getting this message on my browser, why? Warning: Cannot add header information - headers already sent by (output started at /var/www/cookietest.php:2) in
1
2439
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at http://www.macromedia.com/devnet/mx/dreamweaver/articles/php_cart.html. When I try to start a session or create a cookie, I get the following errors. Warning: Cannot send session cache limiter - headers...
6
2513
by: Douglas F. | last post by:
My host doesn't use buffering so I placed the form validation (php) ahead of the html like this: <?php if(isset($_POST)) { <do the validation processing> if(file_exists($fn)) { header("Location: $fn"); <---Bombs } }
5
2525
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already started sending out the content of the page. Web content is always delivered with a few headers at the top, ending with a blank line. For...
2
2537
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
22
2194
by: Platero | last post by:
Hi, I've a stupid question but... The code is the following: if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET))) { $possible_ids = array(2,6,7,8,9,10); $t_id = $_GET;
4
1732
by: craigtomo | last post by:
I am getting the following error when i try to log on to my data base Warning: session_register() : Cannot send session cookie - headers already sent by (output started at D:\virtualservers\182763\root\test\login\checklogin.php:1) in D:\virtualservers\182763\root\test\login\checklogin.php on line 18 Warning: session_register() : Cannot send...
2
2254
by: WALDO | last post by:
I am having the exact same problem. I am using VS2008 (.Net 3.5) and I can't set the Expires date out any further than one day. Doing a little reflection, I see that in the HttpCachePolicy class, SetExpires() method, if the expires is already set, it will only change if the new expiration date is less than the existing one. I have removed...
6
11475
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.