Koozali.org: home of the SME Server

PHP Problem ( Warning: Cannot modify header information )

Offline igardiner

  • *
  • 24
  • +0/-0
PHP Problem ( Warning: Cannot modify header information )
« 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
Totally New to SME

Offline warren

  • *
  • 293
  • +0/-0
Re: PHP Problem ( Warning: Cannot modify header information )
« Reply #1 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

Offline igardiner

  • *
  • 24
  • +0/-0
Re: PHP Problem ( Warning: Cannot modify header information )
« Reply #2 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
Totally New to SME

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: PHP Problem ( Warning: Cannot modify header information )
« Reply #3 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 .
« Last Edit: January 25, 2008, 10:42:20 AM by cactus »
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline judgej

  • *
  • 375
  • +0/-0
Re: PHP Problem ( Warning: Cannot modify header information )
« Reply #4 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.
-- Jason