zgkhoo Posted September 27, 2007 Share Posted September 27, 2007 <?php include 'config.php'; include 'opendb.php'; function LoginF($username,$password){ //echo $username.$password; <---cant enable it $result=mysql_query("SELECT * from person"); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ if(($username==$row['Username'])&&($password==$row['Password'])){ //echo "username success"; <----cant enable it if($row['Level']=='Boss'){ header('Location: bossmenu.php'); } if($row['Level']=='Agent'){ header('Location: agentmenu.php'); } if($row['Level']=='Customer'){ header('Location: customermenu.php'); } if($row['Level']=='Typist'){ header('Location: typistmenu.php'); } } else { // echo "invalid login"; <--cant enable it.. } }// end of while loop }//end of function LoginF if(isset($_POST['createDB'])){ include 'createdb.php'; echo "testing"; } if(isset($_POST['cPerson'])){ echo "cperson"; $sql = "CREATE TABLE person ( Username varchar(13), Password varchar(13), Level varchar(13) )"; mysql_query($sql, $con) or die("Can't execute sql" . mysql_error()); $sql="INSERT INTO person (Username,Password,Level)VALUES ('testing1','testing1','Boss')"; mysql_query($sql, $con); $sql="INSERT INTO person (Username,Password,Level)VALUES ('testing2','testing2','Agent')"; mysql_query($sql, $con); $sql="INSERT INTO person (Username,Password,Level)VALUES ('testing3','testing3','Customer')"; mysql_query($sql, $con); $sql="INSERT INTO person (Username,Password,Level)VALUES ('testing4','testing4','Typist')"; mysql_query($sql, $con); } if(isset($_POST['cTrans'])){ $sql = "CREATE TABLE transaction ( Username varchar(13) )"; mysql_query($sql, $con) or die("Can't execute sql" . mysql_error()); $sql="INSERT INTO transaction (Username) VALUES ('testing')"; mysql_query($sql, $con); } if(isset($_POST['cResult'])){ $sql = "CREATE TABLE Result ( Username varchar(13) )"; mysql_query($sql, $con) or die("Can't execute sql" . mysql_error()); $sql="INSERT INTO Result (Username) VALUES ('testing')"; mysql_query($sql, $con); } if(isset($_POST['Login'])){ //echo "sign in"; LoginF($_POST[username],$_POST[password]); } ?> <html> <body> </br> </br> </br> <center> <h1> Sports Toto </h1> <img src="toto.gif"> <form action="index.php" method="POST"> <h2>Username <input type="text" name="username"/> <br/> Password <input type="password" name="password"/> </h2> <input type="submit" name="Login" value="Log In"> <button name="createDB" value="createDB33"> create db </button> <button name="cPerson">Create person table</button> <button name="cTrans">Create transaction table</button> <button name="cResult">Create result table</button> </form> </center> </body> </html> cant enable the echo above, if i enable it ..will occur error msg.. Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\Sportstoto\index.php:6) in C:\Program Files\xampp\Sportstoto\index.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/ Share on other sites More sharing options...
roopurt18 Posted September 27, 2007 Share Posted September 27, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356161 Share on other sites More sharing options...
d.shankar Posted September 27, 2007 Share Posted September 27, 2007 Yeah it will conflict for sure. Remove the echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356174 Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 Why would you want to echo something on one page then redirect to another anyway? It makes no sense. Even if it was plausible, the client would never see it. Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356179 Share on other sites More sharing options...
Psycho Posted September 27, 2007 Share Posted September 27, 2007 You just need to code around it. Your page should be built so that it first performs the logic THEN outputs the HTML. Something like this: <?php function LoginF($username,$password){ $output = $username.$password."\n"; $result=mysql_query("SELECT * from person"); while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ if(($username==$row['Username'])&&($password==$row['Password'])){ $output = "username success\n"; if($row['Level']=='Boss'){ header('Location: bossmenu.php'); } if($row['Level']=='Agent'){ header('Location: agentmenu.php'); } if($row['Level']=='Customer'){ header('Location: customermenu.php'); } if($row['Level']=='Typist'){ header('Location: typistmenu.php'); } } else { $output = "invalid login\n"; } }// end of while loop echo $output; }//end of function LoginF ?> Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356180 Share on other sites More sharing options...
d.shankar Posted September 27, 2007 Share Posted September 27, 2007 No thorpe.. He want to make the code to work in this manner. if(redirection fails) { then echo the message; } thats it. Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356182 Share on other sites More sharing options...
Psycho Posted September 27, 2007 Share Posted September 27, 2007 No thorpe.. He want to make the code to work in this manner. if(redirection fails) { then echo the message; } thats it. Where do you see that? The code posted shows that IF login passes AND the user is of a specified level THEN he wants to redirect. There is nothing to show that the code is attempting to echo if the redirect fails. However, if login fails or if the user is not of any of the specified levels THEN the messages should be echo'd to the page. Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356187 Share on other sites More sharing options...
zgkhoo Posted September 27, 2007 Author Share Posted September 27, 2007 Why would you want to echo something on one page then redirect to another anyway? It makes no sense. Even if it was plausible, the client would never see it. if fail login then display error msg...if successful login then redirect... Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356188 Share on other sites More sharing options...
trq Posted September 27, 2007 Share Posted September 27, 2007 Why would you want to echo something on one page then redirect to another anyway? It makes no sense. Even if it was plausible, the client would never see it. if fail login then display error msg...if successful login then redirect... That is perfectly valid logic. A psuedo example. <?php if ($loginvalid) { dologin(); header('members.php'); } else { echo 'login failed'; } ?> However, your code does not follow that same logic. Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356190 Share on other sites More sharing options...
d.shankar Posted September 27, 2007 Share Posted September 27, 2007 Where do you see that? The code posted shows that IF login passes AND the user is of a specified level THEN he wants to redirect. There is nothing to show that the code is attempting to echo if the redirect fails. However, if login fails or if the user is not of any of the specified levels THEN the messages should be echo'd to the page. That is what zgkhoo wants to do .. See his post below yours Mr.mjdamato !! http://www.phpfreaks.com/forums/index.php/topic,161014.msg703392.html#msg703392 Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356193 Share on other sites More sharing options...
Psycho Posted September 27, 2007 Share Posted September 27, 2007 Where do you see that? The code posted shows that IF login passes AND the user is of a specified level THEN he wants to redirect. There is nothing to show that the code is attempting to echo if the redirect fails. However, if login fails or if the user is not of any of the specified levels THEN the messages should be echo'd to the page. That is what zgkhoo wants to do .. See his post below yours Mr.mjdamato !! http://www.phpfreaks.com/forums/index.php/topic,161014.msg703392.html#msg703392 Ok, I'm not trying to be rude, but you are totally off. You stated if(redirection fails) { then echo the message; } zgkhoo stated if fail login then display error msg Those are NOT the same. Login failing and Redirection failing are two different things. Off Topic: can you even test if a redirection fails? @zgkhoo Did you try the code I posted? I think it will do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/70845-echo-and-headerlocation-conflict/#findComment-356520 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.