473,698 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot modify header information - headers already sent by (------)

63 New Member
Hi All. I have got problem with the header. If i run my php script in the local host it runs perfectly but if i do the same on net after loading it via ftp. it gives following error:
Warning: Cannot modify header information - headers already sent by (output started at /home2/insat/public_html/search1.php:5) in /home2/insat/public_html/search1.php on line 36

The code goes like this:

[PHP]<html>
<title>CMS:Sear ch Product</title>
<body>

<?php //line 5
include "dbconnect.php" ;
// The basic SELECT statement
$select = 'SELECT DISTINCT pcode,purl ';
$from = ' FROM product';
$where = ' WHERE 1=1 ';
$searchtext = $_POST['searchtext'];

if($searchtext != "")
{
$searchtext = mysql_real_esca pe_string($sear chtext) ;
$where .= " AND pcode = '$searchtext'";
}

?>
// execute the query
<?php
$url = mysql_query($se lect . $from . $where);
// test the result
if (!$url)
{
exit('<p>Error retrieving urls from database!<br />'.
'Error: ' . mysql_error() . '</p>');
echo '<p> no product found</p>' ;
}


while ($lcurl = mysql_fetch_arr ay($url))
{
$id = $lcurl['pcode'];
$pdurl = htmlspecialchar s($lcurl['purl']);
header("Locatio n:$pdurl"); // line 36
}
?>



</body>
</html>[/PHP]

------------------------------------------------------------
please help.
Oct 20 '07 #1
3 1592
ak1dnar
1,584 Recognized Expert Top Contributor
Try to set the "<?php" as the first line of the page like this when dealing with headers.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Php code 
  3. ?>
  4. <html>
  5. <head>
  6. </body>
  7. </body>
  8. </html>
Oct 20 '07 #2
TechnoAtif
63 New Member
Try to set the "<?php" as the first line of the page like this when dealing with headers.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Php code 
  3. ?>
  4. <html>
  5. <head>
  6. </body>
  7. </body>
  8. </html>
=============== =============== =============== =
Hi ajaxrand. Great to hear from u. As for your reply,if i set the first line of the page as u said. Then it is difficult to reposition the header coz,its not alone but is included in the while loop.thhat means the entire loop has to be moved upwards.this will cause great confusion in the script. So can u pleaze elaborate on your reply and specify what modifications to be done with the header.
Thanks
Oct 20 '07 #3
TechnoAtif
63 New Member
My updated code goes like this:

[PHP]<?php
include "dbconnect.php" ;
// The basic SELECT statement
$select = 'SELECT DISTINCT pcode,purl ';
$from = ' FROM product';
$where = ' WHERE 1=1 ';
$searchtext = $_POST['searchtext'];
if($searchtext != "")
{
$searchtext = mysql_real_esca pe_string($sear chtext) ;
$where .= " AND pcode = '$searchtext'";
}
// execute the query
$url = mysql_query($se lect . $from . $where);
// test the result
if (!$url)
{
exit('<p>Error retrieving urls from database!<br />'.
'Error: ' . mysql_error() . '</p>');
echo '<p> no product found</p>' ;
}
while ($lcurl = mysql_fetch_arr ay($url))
{
$id = $lcurl['pcode'];
$pdurl = htmlspecialchar s($lcurl['purl']);
header('Locatio n:$pdurl');
exit;
}
?>[/PHP]
---------------------------------------------------------------------

But still it gives the same error:

Warning: Cannot modify header information - headers already sent by (output started at /home2/insat/public_html/search1.php:4) in /home2/insat/public_html/search1.php on line 30
Oct 20 '07 #4

Sign in to post your reply or Sign up for a free account.

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.