grandadevans Posted August 13, 2006 Share Posted August 13, 2006 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? Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 use a if statement around the $query or database okexample only[code]<?php$test="test.php";if(isset($test)){header("location: whatever.com");}?>[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 Nope,Still not workingThis 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] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 [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] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 [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] Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 I've just tried[code] <?php$loc='forms2.php?sent=' . $row_companyDetails['company']; if (isset($loc)) { header("Location: test.php");?>[/code]and[code]<?phpif (isset($insert)) { header("Location: forms2.php?sent=' . $row_companyDetails['company']"); }?>[/code]For the second one I get a Parse errorRemember that I'm only uising test.php to see if it is definitively failing. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 sorry edited correct code to test if your server header in php working okknow point to test.php should goto goolgle.comtest.php[code]<?phpheader("location: http://www.google.com");?>[/code] Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 That also works Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 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 Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 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);?><?phpif ($_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 companiesif (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 companiesif (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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
redarrow Posted August 13, 2006 Share Posted August 13, 2006 well done we both cracked it yer har !!!!!!!!!!!!!!make sure that you error checking in the php.ini is set to all errors ok Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 13, 2006 Share Posted August 13, 2006 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 Quote Link to comment Share on other sites More sharing options...
grandadevans Posted August 13, 2006 Author Share Posted August 13, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.