Jump to content

Archived

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

dragin99

Trying to redirect to html page without using header variable

Recommended Posts

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.domainname.com/mailinglist/inc/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.

Share this post


Link to post
Share on other sites
[code]
header("location:  success.html");
[/code]

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

Share this post


Link to post
Share on other sites
[!--quoteo(post=372173:date=May 7 2006, 09:43 PM:name=redarrow)--][div class=\'quotetop\']QUOTE(redarrow @ May 7 2006, 09:43 PM) [snapback]372173[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]
header("location:  success.html");
[/code]

[code]
header("location: http://www.domainname.com/mailinglist/inc/success.html");
[/code]
[/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

Share this post


Link to post
Share on other sites
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 [i]sticky[/i] thread again and fix your problems here.

Share this post


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

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.