Jump to content


Photo

header line is being skipped


  • Please log in to reply
19 replies to this topic

#1 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 09:31 AM

Hi all,
Can anybody help me,
I have a script, here are the relevant lines
mysql_query($insert) or die(mysql_error());
	$loc='test.php;
	header("Location: $loc");
	echo "test";
The problem is that it looks like it is just skipping the header line.
After the form has been completed, it completes the MySQL query, just refreshes the same page and echoes the "test" line.

There is no error message or anything, it just skips the line, I have tried it this way and with a direct reference to a page ie
header("Location: test.php")
but that doesn't work either!
Anybody got any ideas?
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 09:35 AM

use a if statement around the $query or database  ok

example only
<?php
$test="test.php";
if(isset($test)){
header("location: whatever.com");
}
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 09:36 AM

why has you test.php got 1 ' <<<<<<<<<<<<<

should be

$what_ever='test.php';


also you code does not look correct if you want to echo a message or redirect the user or both.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 09:43 AM

Nope,
Still not working
This is the actual code that I am using, I was just using test.php as an example to see if it would go to the URL as it would have been a 404 error and easier to spot than looking at the address bar.
$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	if (isset($loc)) {
	header("Location: $loc");
	}
	echo $loc;

Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 09:46 AM


$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	if (isset($loc)) {
	header("Location: http://www.google.com"); <<< the page to goto
	}
	echo $loc;

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 09:51 AM

<?php
$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
           if (isset($insert)) {
	header("Location: 	forms2.php?sent=' . $row_companyDetails['company']");
	}
	?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 09:58 AM

I've just tried
<?php
$loc='forms2.php?sent=' . $row_companyDetails['company'];
	if (isset($loc)) {
	header("Location: test.php");
?>
and
<?php
if (isset($insert)) {
	header("Location: 	forms2.php?sent=' . $row_companyDetails['company']");
	}
?>
For the second one I get a Parse error
Remember that I'm only uising test.php to see if it is definitively failing.
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 10:10 AM

sorry edited correct code to test if your server header in php working ok

know point to test.php should goto goolgle.com

test.php
<?php

header("location: http://www.google.com");

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 10:12 AM

That work's fine.
I have several headers on my site already and have never had a problem that I've not been able to work through by myself before but this one is getting the best of me.
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#10 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 10:14 AM

try this please


if ($_POST['submit']){

$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	header("location: $loc");
	}


this is how i tested the above code if intrested

<?php

$url="http://www.google.com";

if(isset($url)){

header("location: $url");

}else{

echo "sorry $url not set";

}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#11 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 10:31 AM

That also works
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#12 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 10:35 AM


this should be the working code does it work

if ($_POST['submit']){

$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	header("location: $loc");
	}


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#13 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 10:49 AM

The
if ($_POST['submit']){
didn't work as it didn't insert anything in the database.
I changed it to
if (isset($_POST['email'])){
which is a required field and that inserted the record into the db but skipped the header.
It obviously recognises the $loc as when the page refreshes it echoes the $loc as requested.
Here is the code that I have just used.
if (isset($_POST['email'])){
$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	header("location: $loc");
	}
	echo $loc;

Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#14 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 11:12 AM

try this mate sorry.

if (isset($email)){
$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	header("location: $loc");
	}
	echo $loc;

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#15 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 11:20 AM

That echoes the right URL
forms2.php?sent=Argos
but it just echoes it, it still skips the header.
I've tried a few things.
I put a header at the head of the page and it worked fine.
I've moved the script as far up the page as possible and it still does not work, the only code infornt of it is
<?php 
require_once('Connections/campaign.php'); 
$company=$_POST['id'];
mysql_select_db($database_campaign, $campaign);
$query_companies = "SELECT DISTINCT entryID, company, companyEmail, URL FROM BFPO_unfriendly WHERE company IS NOT NULL";
$companies = mysql_query($query_companies, $campaign) or die(mysql_error());
$row_companies = mysql_fetch_assoc($companies);

$query_companyDetails=sprintf("SELECT entryID, company FROM BFPO_unfriendly WHERE companyEmail LIKE '$company';");
$companyDetails=mysql_query($query_companyDetails, $campaign) or die (mysql_error());
$row_companyDetails=mysql_fetch_assoc($companyDetails);

if ($_POST['Submit']) {
	require("phpmailer/class.phpmailer.php");
	$companyID=$row_companyDetails['entryID'];
	$IP=$_SERVER['REMOTE_ADDR'];
	$email=$_POST['email'];
	$name=$_POST['name'];
	$message=$_POST['description'];
	$subject=$_POST['subject'];
if ($_POST['id'] !== 'all') {
This one has got me totally flustered
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#16 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 11:30 AM

Got IT!
I changed it from
	<?php require_once('Connections/campaign.php'); ?>
<?php
$company=$_POST['id'];
mysql_select_db($database_campaign, $campaign);
$query_companies = "SELECT DISTINCT entryID, company, companyEmail, URL FROM BFPO_unfriendly WHERE company IS NOT NULL";
$companies = mysql_query($query_companies, $campaign) or die(mysql_error());
$row_companies = mysql_fetch_assoc($companies);
$totalRows_companies = mysql_num_rows($companies);

$query_companyDetails=sprintf("SELECT entryID, company FROM BFPO_unfriendly WHERE companyEmail LIKE '$company';");
$companyDetails=mysql_query($query_companyDetails, $campaign) or die (mysql_error());
$row_companyDetails=mysql_fetch_assoc($companyDetails);

?><?php
if ($_POST['Submit']) {
	require("phpmailer/class.phpmailer.php");
	$companyID=$row_companyDetails['entryID'];
	$IP=$_SERVER['REMOTE_ADDR'];
	$email=$_POST['email'];
	$name=$_POST['name'];
	$message=$_POST['description'];
	$subject=$_POST['subject'];
if ($_POST['id'] !== 'all') {
//Start of email to individual companies
if (isset($email)){
$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	header("location: $loc");
to
<?php 
require_once('Connections/campaign.php');
$company=$_POST['id'];
mysql_select_db($database_campaign, $campaign);
$query_companies = "SELECT DISTINCT entryID, company, companyEmail, URL FROM BFPO_unfriendly WHERE company IS NOT NULL";
$companies = mysql_query($query_companies, $campaign) or die(mysql_error());
$row_companies = mysql_fetch_assoc($companies);
$totalRows_companies = mysql_num_rows($companies);

$query_companyDetails=sprintf("SELECT entryID, company FROM BFPO_unfriendly WHERE companyEmail LIKE '$company';");
$companyDetails=mysql_query($query_companyDetails, $campaign) or die (mysql_error());
$row_companyDetails=mysql_fetch_assoc($companyDetails);

if ($_POST['Submit']) {
	require("phpmailer/class.phpmailer.php");
	$companyID=$row_companyDetails['entryID'];
	$IP=$_SERVER['REMOTE_ADDR'];
	$email=$_POST['email'];
	$name=$_POST['name'];
	$message=$_POST['description'];
	$subject=$_POST['subject'];
if ($_POST['id'] !== 'all') {
//Start of email to individual companies
if (isset($email)){
$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
	header("location: $loc");
And now it works, I've undone and redone it a few times to make sure and the problem is solved.
looking at it, it may have been the indent before the
	<?php require_once('Connections/campaign.php'); ?>
but then surely it would have come up with an error saying that the header was already sent
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 11:32 AM

trying everthink man it's a joke lol.....................

try this ok.

$insert ="INSERT INTO emails_sent (companyID, name, email, message, IP) VALUES ('$companyID', '$name', '$email', '$message', INET_ATON('$IP'));";
	mysql_query($insert) or die(mysql_error());
	$loc='forms2.php?sent=' . $row_companyDetails['company'];
             if (isset($email)){
	header("location: $loc");
	}
	echo $loc;

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 11:34 AM

well done we both cracked it


yer har !!!!!!!!!!!!!!

make sure that you error checking in the php.ini is set to all errors ok
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#19 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 13 August 2006 - 11:34 AM

Do you mean that you're running all this with error_reporting turned off? If so, it's no wonder there were apparently no errors.

http://ca.php.net/ma...r-reporting.php
Legend has it that reading the manual never killed anyone.
My site

#20 grandadevans

grandadevans
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 13 August 2006 - 11:37 AM

No,
I had the whitespace problem only last week, but I know what to look for when I get that 'header already sent error' and I've changed nothing since then.
Please sign our petition and support our troops<br />
<a href="http://www.postedove...ition.php"><img src="http://www.postedove...o_campaign.jpg" /></a>




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users