Koozali.org: home of the SME Server

Obsolete Releases => SME 7.x Contribs => Topic started by: igardiner on January 24, 2008, 05:12:41 AM

Title: PHP Problem ( Warning: Cannot modify header information )
Post by: igardiner on January 24, 2008, 05:12:41 AM
Hi All

Sorry if I am posting this in the wrong place but I have been having a bit of a problem with php on SME 7.3. I have a script that inserts data into my MYSQL database on the SME server. All appears to be going ok and the data is saving, however when I try to redirect a user back to the cms_referencetables.php page I get the following error

Warning: Cannot modify header information - headers already sent by (output started at /home/e-smith/files/ibays/phptest/html/cms/scripts/proc_referencetables_insert.php:14) in /home/e-smith/files/ibays/phptest/html/cms/scripts/proc_referencetables_insert.php on line 22

My script is as below:

<?php require_once('Connections/IntanetDev.php'); ?>

<?php
$query_insert_referencetables = "INSERT INTO ReferenceTables (TableDesc, URLPage, ActiveInd) VALUES ('".$_POST['TableDesc']."', '".$_POST['URLPage']."', '".$_POST['ActiveInd']."');" ;

$rs_insertreferencetables = mysql_query($query_insert_referencetables);

header("Location: cms_referencetables.php
?>

I have been searching through google and php forums and have found a lot of solutions for people running Micro$oft and II$ solutions and have tried some of them all to no avail, but don't really know where to start next (new to PHP, MYSQL and Linux, sorry all)!

If anybody could point me in the right direction that would be greatly appreciated.

Thanks
Title: Re: PHP Problem ( Warning: Cannot modify header information )
Post by: warren on January 24, 2008, 07:07:05 AM
Hi Igardiner,
not really and SME problem, however try adding an exit statement after the header function call

Code: [Select]
header("Location: cms_referencetables.php
exit(0);
?>

also check out the php manual

http://www.php.net/manual/en/function.header.php (http://www.php.net/manual/en/function.header.php)
Title: Re: PHP Problem ( Warning: Cannot modify header information )
Post by: igardiner on January 25, 2008, 03:09:23 AM
Thanks for info.

I know it wasn't really an SME question/problem but when I read through a lot of the google search results they talked about configuration in the php.ini file so I thought maybe I had missed something somewhere in SME.

Thanks once again for the links
Title: Re: PHP Problem ( Warning: Cannot modify header information )
Post by: cactus on January 25, 2008, 10:38:34 AM
Warning: Cannot modify header information - headers already sent by (output started at /home/e-smith/files/ibays/phptest/html/cms/scripts/proc_referencetables_insert.php:14) in /home/e-smith/files/ibays/phptest/html/cms/scripts/proc_referencetables_insert.php on line 22
This is a very basic PHP error and means you have already started outputting data (probably because of an error or something like that) to the browser and then trying to redirect. Fix your error and if there is no error, perhaps you need to rewrite your code or make use of output_buffering, all necessary information should be in the php manual at http://www.php.net .
Title: Re: PHP Problem ( Warning: Cannot modify header information )
Post by: judgej on January 26, 2008, 06:11:47 PM
You can't send headers (line 22) after output of some other type has already started (which it has on line 14). Check what line 14 does, and stop it outputting whatever it is outputting.