Redirect header is getting error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nigil
Forum Newbie
Posts: 1
Joined: Fri Feb 25, 2011 3:43 am

Redirect header is getting error

Post by nigil »

Hi my name is nigil,

This is my first php help question ever to any website as I am a newbie. I have a script which searches a value called serial number and finds its other fields like name and warranty. This all works fine, the thing is when there is an serial been put which is not in the database it should redirect to the missing.html This part is i am getting error message given below:
Warning: Cannot modify header information - headers already sent by (output started at /home/bjventur/public_html/it@school/welcome.php:5) in /home/bjventur/public_html/it@school/welcome.php on line 39

Please Help my My full php code is given below:

<HTML><HEAD>
<TITLE>Details</TITLE>
<style type="text/css">
BODY { COLOR: #0000FF; FONT: 12px verdana, arial, sans-serif; font-weight: normal }
</style>
<link rel="stylesheet" type="text/css" href="style.css" />
</HEAD> <BODY bgColor="#FFFFFF">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center"><br>
<br>
<font color="#333333">Welcome Dear Mr. <?php echo $_POST["txtname"]; ?>, Please
find below the details you have inquired;</font></p>
<p align="center">&nbsp;</p><br><br><br><br><br><br>
<p align="center"><strong><br>
<?php
$txtserial = $_POST['txtserial'];
// Make a MySQL Connection
mysql_connect("localhost", "bjventur_basha", "nagma@rajani11") or die(mysql_error());
mysql_select_db("bjventur_test") or die(mysql_error());

// Get a specific result from the "dikon" table

$result = mysql_query("SELECT * FROM bjventur_dikon
WHERE serial='$txtserial'") or die(mysql_error());

// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array( $result );
if ($row == 0)
{
header('Location: http://www.website.com/missing.html');
}
else
{
}


// Print out the contents of each row into a table
echo " Serial Number: " .$row['serial'];
echo "<br />";
echo "<br />";
echo " Customer Name: ".$row['name'];
echo "<br />";
echo "<br />";
echo " Warranty upto: ".$row['warranty'];
?>
</strong></p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p align="center"><font color="#333333">For Service Please call at <strong>008-8803-333</strong></font></p>
<p align="center"><font color="#333333"><em>Thank you for visiting!</em></font></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">
<p><font color="#666666" size="2" face="Arial, Helvetica, sans-serif">
</font></p>
<p><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif">Powered
by</font><font color="#666666" size="1" face="Arial, Helvetica, sans-serif">
<a href="http://www.website.com" target="_blank" style="text-decoration:none"><font color="#FFFFFF">nigil</font></a></font></p>
</div></td>
</tr>
</table>
<p>&nbsp; </p>
</BODY></HTML>
divedj
Forum Commoner
Posts: 47
Joined: Wed Dec 29, 2010 4:32 am
Location: Malta

Re: Redirect header is getting error

Post by divedj »

You need to place your header request before any output is made including <html> tags. Try to get your db calls and validations on top of your page, before any output is made to the browser and the redirect will work.
Post Reply