Solved

PHP Warning: Cannot modify header information - headers already sent by...

Posted on 2007-12-01
4
1,408 Views
Last Modified: 2013-12-12
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/db/mysql4.php on line 317

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/db/mysql4.php on line 317

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/db/mysql4.php:317) in /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/includes/page_header.php on line 479

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/db/mysql4.php:317) in /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/includes/page_header.php on line 485

Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/db/mysql4.php:317) in /mounted-storage/home43a/sub004/sc31952-BMDX/www/forum/includes/page_header.php on line 486


I keep getting that warning in lines 479, 485 and 486, here is the code of that file at those lines of the page_header.php:

// Work around for "current" Apache 2 + PHP module which seems to not
// cope with private cache control setting
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2'))
{
      header ('Cache-Control: no-cache, pre-check=0, post-check=0'); //line 479
}
else
{
      header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
}
header ('Expires: 0');//line 485
header ('Pragma: no-cache'); //line 486

$template->pparse('overall_header');

?>

Code of the mysql4.php:

            if ( $query_id )
            {
                  unset($this->row[$query_id]);
                  unset($this->rowset[$query_id]);
                  mysql_free_result($query_id); //line 317

                  return true;
            }

What am I doing wrong?
0
Comment
Question by:axtur
4 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20390142
axtur:

There is nothing wrong with your line 479, it is simply because your error messages for your mysql_free_result(): function has been written to the browser, therefore the header() function cannot execute properly.

Solving the mysql_free_result(): error message will also solve your other errors!

Hope this helps.
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 20390370
mysql_free_result($query_id); is not a resource.

you should first check if its a resource and then use mysql_free_result. mysql_query() will only return a resource on SELECT, SHOW, EXPLAIN and DESCRIBE queries.

use this code to check.
 if ( $query_id )
            {
                  unset($this->row[$query_id]);
                  unset($this->rowset[$query_id]);
				  if(is_resource($query_id)) {
                     
					 mysql_free_result($query_id); 
				  
				  }
                  return true;
            }	  

Open in new window

0
 
LVL 14

Expert Comment

by:profya
ID: 20390739
The problem is with line 317, make sure that you are connected to the database before you can run a query.
0
 

Author Closing Comment

by:axtur
ID: 31412158
Excellent.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question