Problem with header()

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Problem with header()

Post by nutstretch »

I ahve a page which is updataing a database and then sending a confirmation email. It shoule then go to a page saying cheers.

I am getting an error "
Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site8/fst/var/www/html/dbshoes/InsertCustomer.php:9) in /home/virtual/site8/fst/var/www/html/dbshoes/InsertCustomer.php on line 107"

The databse is updating and the email is being sent.

below is my code:

$Firstname = $_POST["requiredName"];
$Surname = $_POST["requiredLastname"];
$Title = $_POST["requiredTitle"];
$Add1 = $_POST["requiredAdd1"];
$Add2 = $_POST["Add2"];
$City = $_POST["requiredCity"];
$County = $_POST["requiredCounty"];
$Postcode = $_POST["requiredPostCode"];
$Phone = $_POST["CustPhone"];
$email = $_POST["requiredEmail"];
$Shoesize = $_POST["requiredShoeSize"];
$Width = $_POST["requiredwidth"];
$Gender = $_POST["requiredGender"];
$Passw = $_POST["requiredPass"];
$Agree = $_POST["requiredAgree"];
$radd = $_POST["requiredEmail"];
$thanks = $_POST["thank"];
$sAddr = $_POST["senderaddr"];
$result = mysql_query("INSERT INTO tblcustomer( Firstname, Surname, Title, CustStreet, CustTown, CustCity, CustCounty, Postcode, CustPhone, CustEmail, DateEntered, ShoeSize, CustWidth, CustGender, LoginID, Agreed) VALUES( '$Firstname', '$Surname', '$Title', '$Add1', '$Add2', '$City', '$County', '$Postcode', '$Phone', '$email', '$date', '$Shoesize', '$Width', '$Gender', '$Passw', '$Agree')", $linkID)or die(mysql_error());

if ($result == true)
{
//print "Thank you for registering an email will be sent shortly confirming you details<p>";
$mail = ("
DB Shoes website Registration\n
---------------------------------------------------------------------\n
Thank you for registering to receive news on new products and services. \n
Please check the details below to ensure they are correct\n\n

Firstname: $Firstname \n
Surnamename: $Surname \n
Tittle: $Title \n
Address Line 1: $Add1 \n
Address Line 2: $Add2 \n
City: $City \n
County: $County \n
Post Code: $Postcode\n
Email address: $email \n
Phone: $Phone \n
Shoesize: $Shoesize \n
Width: $Width \n
Gender: $Gender \n
\n
Your password is: $Passw \n
\n
Your login username is your email address \n

---------------------------------------------------------------------\n
DB Shoes Limited, Irchester Road, Rushden, Northamptonshire NN10 9XF, England\n
Tel: +44 (0)1933 359217 Fax: +44 (0)1933 410218 Email: enquiries@dbshoes.co.uk\n

");

mail( $radd, $subject,
$mail, "From: $sAddr" );
header( "Location: $thanks" );

Any help appreciated
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

somethings missing ... the error means that you are outputting something from your script on line 107 but I dont see 107 lines here!

have a look for some type of output on line 107 or give us the full script.
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

I had the mail script aspart of an if statement and I'm not sure it liked it. When i said put the result here (Your email has been sent) after the mail had gone and deleted the header line (107) it was ok.

Was it because it was part of the iff statement and not on it;'s own

<p><?php
$date = getdate();
$linkID = @mysql_connect("localhost", "astokes", "beebo1");
mysql_select_db("beebosoft_net_-_DBShoes", $linkID);
//$linkID = @mysql_connect("localhost", "root", "");
//mysql_select_db("DBShoes", $linkID);
$Firstname = $_POST["requiredName"];
$Surname = $_POST["requiredLastname"];
$Title = $_POST["requiredTitle"];
$Add1 = $_POST["requiredAdd1"];
$Add2 = $_POST["Add2"];
$City = $_POST["requiredCity"];
$County = $_POST["requiredCounty"];
$Postcode = $_POST["requiredPostCode"];
$Phone = $_POST["CustPhone"];
$email = $_POST["requiredEmail"];
$Shoesize = $_POST["requiredShoeSize"];
$Width = $_POST["requiredwidth"];
$Gender = $_POST["requiredGender"];
$Passw = $_POST["requiredPass"];
$Agree = $_POST["requiredAgree"];
$radd = $_POST["requiredEmail"];
$thanks = $_POST["thank"];
$sAddr = $_POST["senderaddr"];
$result = mysql_query("INSERT INTO tblcustomer( Firstname, Surname, Title, CustStreet, CustTown, CustCity, CustCounty, Postcode, CustPhone, CustEmail, DateEntered, ShoeSize, CustWidth, CustGender, LoginID, Agreed) VALUES( '$Firstname', '$Surname', '$Title', '$Add1', '$Add2', '$City', '$County', '$Postcode', '$Phone', '$email', '$date', '$Shoesize', '$Width', '$Gender', '$Passw', '$Agree')", $linkID)or die(mysql_error());

if ($result == true)
{
$mail = ("
DB Shoes website Registration\n
---------------------------------------------------------------------\n
Thank you for registering to receive news on new products and services. \n
Please check the details below to ensure they are correct\n\n

Firstname: $Firstname \n
Surnamename: $Surname \n
Tittle: $Title \n
Address Line 1: $Add1 \n
Address Line 2: $Add2 \n
City: $City \n
County: $County \n
Post Code: $Postcode\n
Email address: $email \n
Phone: $Phone \n
Shoesize: $Shoesize \n
Width: $Width \n
Gender: $Gender \n
\n
Your password is: $Passw \n
\n
Your login username is your email address \n

---------------------------------------------------------------------\n
DB Shoes Limited, Irchester Road, Rushden, Northamptonshire NN10 9XF, England\n
Tel: +44 (0)1933 359217 Fax: +44 (0)1933 410218 Email: enquiries@dbshoes.co.uk\n

");

mail( $radd, $subject,
$mail, "From: $sAddr" );
//header( "Location: $thanks" );

print "Thank you. An email will be sent shortly";
}
else
{
print "There is an error with the code on this page please contact the administrator<p>";
}

mysql_close($linkID);

?></p>

PS the date thing isn't working have i the wrong syntax?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

its the <p> tag before you enter the php, any output to the browser before a call to the header() function will prevent the header() from working.

for the getdate() you are using the wrong function, use date() and specify a format, check the PHP site to find out the formatting for this function!
Post Reply