Timinator2000 Posted November 15, 2007 Share Posted November 15, 2007 Ok, I am having a hard time with the header function.. if you look at the script below, both the 2 first header functions work no problem upon given cirumstances.. but as soon as I add the last header function, the first header function does not work.. it always reverts to the last header.. what am i doing wrong? Thanks everyone. CODE: <? //------------------------------------------------------------------------------------------------------------------ // VARIABLE DECLARATION.. $username = $_GET['user']; $password = $_GET['password']; $Button = $_GET['Button']; //------------------------------------------------------------------------------------------------------------------ // FUNCTION LOGIN INTO LOGIN DATABASE function readdata() { ...deleted for posting purposes..} //------------------------------------------------------------------------------------------------------------------ if ($Button == "Cancel"){ @header("Location: http://www.xxx.com/Mainview.php?selected=poker"); } if ($Button == "Submit"){ !readdata(); $query="SELECT * FROM `login`"; $result=mysql_query($query) or die("Query failed: $query\nError: " . mysql_error()); $num_entries=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num_entries) { $sqluser=mysql_result($result,$i,'user'); $sqlpass=mysql_result($result,$i,'pass'); if ($username == $sqluser && $password == $sqlpass) { @header("Location: http://www.xxx.com/test2.php"); } $i++; } } @header("Location: http://www.xxx.com/signin.php?flag=invalid"); ?> Quote Link to comment Share on other sites More sharing options...
kopytko Posted November 15, 2007 Share Posted November 15, 2007 Remove @ from code and check if there are any warning or errors. I supose that threre is some text outputed before header and this is the reason of your problem. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 15, 2007 Share Posted November 15, 2007 Well, your last header() is run no matter what. Is that what you want? Adding an exit; very last inside the two if statements will fix it (causing the script to stop executing and thus not running your last header function). Quote Link to comment Share on other sites More sharing options...
Timinator2000 Posted November 15, 2007 Author Share Posted November 15, 2007 The exit; did it.. i wanted the last header to run if the 2 header conditions were not met.. I didn't think that, if the 1st condition was met, that it would continue on to the last header... just learned something new today! Thanks for you help! Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 15, 2007 Share Posted November 15, 2007 You're welcome And in the future, maybe consider using if, elseif, else if you want to do something if two conditions aren't met. <?php if (first condition) { //do something if first condition is met; } elseif (second condition) { //do something if first condition isn't met, but the second is; } else { //do something if none of the conditions were met; } ?> But it is always a good idea to exit your script after a header redirect. 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.