Header Problem in PHP
Posted: Thu May 20, 2004 8:33 am
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();
}
}
}
?>
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();
}
}
}
?>