Jump to content

Archived

This topic is now archived and is closed to further replies.

grandadevans

header line is being skipped

Recommended Posts

Hi all,
Can anybody help me,
I have a script, here are the relevant lines
[code] mysql_query($insert) or die(mysql_error());
$loc='test.php;
header("Location: $loc");
echo "test";
[/code]
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
[code]header("Location: test.php") [/code]
but that doesn't work either!
Anybody got any ideas?

Share this post


Link to post
Share on other sites
use a if statement around the $query or database  ok

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.
[code] $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;
[/code]

Share this post


Link to post
Share on other sites
[code]

$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;[/code]

Share this post


Link to post
Share on other sites
[code]
<?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']");
}
?>
[/code]

Share this post


Link to post
Share on other sites
I've just tried
[code] <?php
$loc='forms2.php?sent=' . $row_companyDetails['company'];
if (isset($loc)) {
header("Location: test.php");
?>
[/code]
and
[code]<?php
if (isset($insert)) {
header("Location: forms2.php?sent=' . $row_companyDetails['company']");
}
?>[/code]
For the second one I get a Parse error
Remember that I'm only uising test.php to see if it is definitively failing.

Share this post


Link to post
Share on other sites
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
[code]
<?php

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

?>
[/code]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
try this please

[code]

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");
}

[/code]

this is how i tested the above code if intrested

[code]
<?php

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

if(isset($url)){

header("location: $url");

}else{

echo "sorry $url not set";

}

?>
[/code]

Share this post


Link to post
Share on other sites

this should be the working code does it work
[code]

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");
}

[/code]

Share this post


Link to post
Share on other sites
The
[code]if ($_POST['submit']){
[/code]
didn't work as it didn't insert anything in the database.
I changed it to
[code]if (isset($_POST['email'])){
[/code]
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.
[code]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;
[/code]

Share this post


Link to post
Share on other sites
try this mate sorry.

[code]
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;
[/code]

Share this post


Link to post
Share on other sites
That echoes the right URL
[code]forms2.php?sent=Argos[/code]
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
[code]<?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') {
[/code]
This one has got me totally flustered

Share this post


Link to post
Share on other sites
Got IT!
I changed it from
[code]
<?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");
[/code]
to
[code]<?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");
[/code]
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
[code]
<?php require_once('Connections/campaign.php'); ?>[/code]
but then surely it would have come up with an error saying that the header was already sent

Share this post


Link to post
Share on other sites
trying everthink man it's a joke lol.....................

try this ok.

[code]
$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;
[/code]

Share this post


Link to post
Share on other sites
well done we both cracked it


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

make sure that you error checking in the php.ini is set to all errors ok

Share this post


Link to post
Share on other sites
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/manual/en/function.error-reporting.php

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.