Header Problem in PHP

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
Gopi
Forum Newbie
Posts: 1
Joined: Thu May 20, 2004 8:33 am

Header Problem in PHP

Post by Gopi »

When storing the details received from Html page, I got this error message.


Warning: Cannot modify header information - headers already sent by (output started at D:\domains\cddda.com\wwwroot\hichennai\savestepone.php:2) in D:\domains\cddda.com\wwwroot\hichennai\savestepone.php on line 60


The code i use is given below :



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
include 'global.php';
$sql="select * from canddetails where uname='" . $_POST['txtuname'] . "'";
$conn=mysql_connect($localhost,$myuser,$mypwd);
$db=mysql_select_db($dbname,$conn);
$result=mysql_query($sql,$conn);
$norows=mysql_num_rows($result);
$flag=false;
if (isset($_GET['txtNocomp'])==true)
{
if ($_GET['txtNocomp']=="")
{
$nocomp="";
$flag=false;
}
else
{
$nocomp=$_GET['txtNocomp'];
$flag=true;
}
}
$uname=$_POST['txtuname'];
$candname=$_POST['txtcandname'];
$dob=$_POST['cmbdate'] . "/" . $_POST['cmbmonth'] . "/" . $_POST['cmbyear'];
$age =$_POST['txtage'];
$address =$_POST['txtaddr'];
$city=$_POST['txtcity'];
$state=$_POST['txtstate'];
$phoneno=$_POST['txtphonecode'] . "-" . $_POST['txtphoneno'];
$email=$_POST['txtemail'];
$totexp=$_POST['txttotexp'];
$qualification=$_POST['txtqualification'];
$jobcategory=$_POST['txtjobcategory'];
$country=$_POST['txtcountry'];
$lang=$_POST['txtlangknown'];
//$norec=$_GET['norec'];
if ($norows>0)
{
$sql="update canddetails set uname='" . $uname . "',candname='" . $candname . "',dateofbirth ='" . $dob . "',age=" . $age . ",address='" . $address . "',city='" . $city . "',state='" . $state . "',phoneno'" . $phoneno . "',email='" . $email . "',totexp=" . $totexp . ",qualification='" . $qualification . "',jobcategory='" . $jobcategory . "',country='". $country . "',langknown='" . $lang . "')";
$result=mysql_query($sql,$conn);
if ($nocomp != "")
{
header("Location: previous_exp.php?txtNocomp=". $nocomp . "&txtuname=" . $_POST['txtuname']);
exit();
}
else
{
header("Location: previous_exp.php?txtuname=" . $_POST['txtuname']);
exit();
}
}
else
{
if ($flag==false)
{
$sql="insert into canddetails(uname,candname,dateofbirth,age,address,city,state,phoneno,email,totexp,qualification,jobcategory,country,langknown) values('" . $uname . "','" . $candname . "','" . $dob . "'," . $age . ",'" . $address . "','" . $city . "','" . $state . "','" . $phoneno . "','" . $email . "'," . $totexp . ",'" . $qualification . "','" . $jobcategory . "','". $country . "','" . $lang . "')";
$result=mysql_query($sql,$conn);
header("Location: previous_exp.php?txtuname=" . $_POST['txtuname']);
exit();
}
else
{
$sql="insert into canddetails(norec,uname,candname,dateofbirth,age,address,city,state,phoneno,email,totexp,qualification,jobcategory,country,langknown) values(" . $nocomp . ",'" . $uname . "','" . $candname . "','" . $dob . "'," . $age . ",'" . $address . "','" . $city . "','" . $state . "','" . $phoneno . "','" . $email . "'," . $totexp . ",'" . $qualification . "','" . $jobcategory . "','". $country . "','" . $lang . "')";
$result=mysql_query($sql,$conn);
if ($nocomp != "")
{
header("Location: previous_exp.php?txtNocomp=". $nocomp . "&txtuname=" . $_POST['txtuname']);
exit();
}
else
{
header("Location: previous_exp.php?txtuname=" . $_POST['txtuname']);
exit();
}
}
}
?>
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

If you are using header() function you should not send anything to the browser before, like here you send the following line:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

http://php.net/header
leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

Post by leenoble_uk »

You're using the Header() function to redirect to another page AFTER you have already sent some information to the client.
You've already sent the DOCTYPE information. You can't send ANY information at all before declaring a header.
You'll have to restructure your document to not send out the DOCTYPE until a decision is made on which page is being sent.
leenoble_uk
Forum Contributor
Posts: 108
Joined: Fri May 03, 2002 10:33 am
Location: Cheshire
Contact:

Post by leenoble_uk »

curse my inadequate slow typeage!
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

leenoble_uk wrote:curse my inadequate slow typeage!
[Off Topic]: Happens all the time :P
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Read this The complete solution to your question is...

Then read this Warning: Cannot add header information

Take notes, and use what you learn.

Mark
Post Reply