dragin99 Posted May 8, 2006 Share Posted May 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 8, 2006 Share Posted May 8, 2006 [code]header("location: success.html");[/code][code]header("location: http://www.domainname.com/mailinglist/inc/success.html");[/code] Quote Link to comment Share on other sites More sharing options...
dragin99 Posted May 8, 2006 Author Share Posted May 8, 2006 [!--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 Quote Link to comment Share on other sites More sharing options...
trq Posted May 8, 2006 Share Posted May 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 8, 2006 Share Posted May 8, 2006 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. 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.