Gnub Posted March 29, 2007 Share Posted March 29, 2007 Ok, i have a simple script that checks the username and password of a user, if it is true, it send the person to address1, if it is false, it send the user to another page. I've covered the basics, but im gettting a: " Warning: Cannot modify header information - headers already sent by (output started at /web/log.php:9) in /web/log.php on line 21 " <?PHP $User = $_POST["Username"]; $Password = $_POST["Password"]; $sql = "Select * FROM `Account` WHERE `Username` = '$User' AND `Password` = '$Password'"; if (mysql_num_rows($result) >"0") { header("location: http://www.Yahoo.com"); echo 'Login Details accepted, you are now being forwarded to the main page...'; } if (mysql_num_rows($result) =="0") { echo 'You are now being forwarded to somewhere else; header("location: http://www.bbc.co.uk"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/ Share on other sites More sharing options...
genericnumber1 Posted March 29, 2007 Share Posted March 29, 2007 you cant output text to the browser and then use a header redirect. read the faqs and the stickies, especially the ones in all caps before you post next time. http://www.phpfreaks.com/forums/index.php/topic,95562.0.html http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/#findComment-217555 Share on other sites More sharing options...
jguy Posted March 29, 2007 Share Posted March 29, 2007 Make 100% sure that you have no HTML tags above this code: (In other words): <HTML><HEAD></HEAD> <BODY> <?PHP $User = $_POST["Username"]; $Password = $_POST["Password"]; $sql = "Select * FROM `Account` WHERE `Username` = '$User' AND `Password` = '$Password'"; if (mysql_num_rows($result) >"0") { header("location: http://www.Yahoo.com"); echo 'Login Details accepted, you are now being forwarded to the main page...'; } if (mysql_num_rows($result) =="0") { echo 'You are now being forwarded to somewhere else; header("location: http://www.bbc.co.uk"); } ?> </BODY> </HTML> Any HTML tags before this will cause the header to function improperly. Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/#findComment-217559 Share on other sites More sharing options...
MadTechie Posted March 29, 2007 Share Posted March 29, 2007 remove the echo's if you MUST have a page telling the user their being redirected then create a redirect page that uses javascript to redirect them as a side note i'm sure you should have if (mysql_num_rows($result) >0) instead of if (mysql_num_rows($result) >"0") same for the == Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/#findComment-217560 Share on other sites More sharing options...
Anzeo Posted March 29, 2007 Share Posted March 29, 2007 Your header tags need to be at the top of your code, right after <php, otherwise you'll get this error. Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/#findComment-217561 Share on other sites More sharing options...
Gnub Posted March 29, 2007 Author Share Posted March 29, 2007 thanks for the help, script now works. Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/#findComment-217563 Share on other sites More sharing options...
MadTechie Posted March 29, 2007 Share Posted March 29, 2007 the Header tag doesn't need to at the top.. just remove the echos.. also click solved (bottom in the blue bar) Quote Link to comment https://forums.phpfreaks.com/topic/44805-solved-forward-to-page-if-username-is-valid/#findComment-217566 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.