Jump to content


Photo

Trying to redirect to html page without using header variable


  • Please log in to reply
4 replies to this topic

#1 dragin99

dragin99
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 May 2006 - 02:37 AM

Hello,
Hopefully this is a simple problem to you all!
I have been using a simple mailing list script successfully for quiet awhile, but I have redisgned the site and now instead of echoing a success or error message I want to redirect to an html page. Seeing as how I am not outputting any data and considering the location of the variables... what variable and syntax can I use to do this! header doesn't seem appropiate because I'm not outputting any data.
here is a sample section of the script:

function insert_mail() {

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];


$sql2="select * from mail where email='$email'";
$result2=mysql_query($sql2) or die("select fails");
$no=mysql_num_rows($result2);



if ($no==0) {


$sql = "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')";
$result = mysql_query($sql) or die("insert fails");

echo "Email added to list: " . LISTNAME;

} else {

header("http://www.domainnam...c/success.html");

}


Tried this and it errored out ( yes I read the section that addresses this but I don't think I should be using header variable anyway.


#2 redarrow

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

Posted 08 May 2006 - 02:43 AM

header("location:  success.html");

header("location: http://www.domainname.com/mailinglist/inc/success.html");

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 dragin99

dragin99
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 May 2006 - 03:43 AM

[!--quoteo(post=372173:date=May 7 2006, 09:43 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ May 7 2006, 09:43 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
header("location:  success.html");

header("location: http://www.domainname.com/mailinglist/inc/success.html");
[/quote]


Problem is I tried that and I receive the "headers already sent errors...thought maybe it was the placement of the code not the code itself. Is there another way to redirect without using the header variable

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 08 May 2006 - 03:45 AM

header() is a function not a variable, and no, you cannot redirect any other way in php. You could use javascripts meta refresh, or, read the sticky thread again and fix your problems here.

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 May 2006 - 06:31 PM

The reason why you are getting the error message is becuase you are outputting something to the browser. You cannot use the header function if you have ouput before the use of header or anyother header style function such as setcookie, session_start etc.

You can use the old html style which is a meta refresh instead.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users