Jump to content

header line is being skipped


grandadevans

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?
Link to comment
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]
Link to comment
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]
Link to comment
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]
Link to comment
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.
Link to comment
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]
Link to comment
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]
Link to comment
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]
Link to comment
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]
Link to comment
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
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.