Jump to content

Trying to redirect to html page without using header variable


dragin99

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.
Link to comment
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
Link to comment
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.
Link to comment
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.
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.