Vivid Lust Posted July 27, 2008 Share Posted July 27, 2008 Hey guys, this login that i made isn't working!! Problems: - When trying to login (entering incorrect info) the page refreshes as it should but no error message appears! ??? - When entering correct details page doesn't redirect to index2.php ??? code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin</title> <link rel="stylesheet" href="style/css.css" /> </head> <body> <?php require_once "require/db.php"; if($_GET['msg'] != ""){ echo htmlentities($_GET['msg']); echo "<br />"; mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $usrname = $_POST['usrname']; $pass = $_POST['pass']; if($usrname && $pass !== ""){ $usrname = stripslashes($usrname); $pass = stripslashes($pass); $usrname = mysql_real_escape_string($usrname); $pass = mysql_real_escape_string($pass); $pass = md5($pass); $sql="SELECT * FROM $db_name WHERE username='$usrname' and password='$pass'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ header("location:index2.php"); } else { header("location: index.php?msg=Incorrect Username or Password. Please try again."); } } } ?> <form action="index.php" enctype="multipart/form-data" method="post"> <b>Username</b><br /> <input type="text" name="usrname" /><br /> <b>Password</b><br /> <input type="password" name="pass" /><br /> <input type="submit" value="Login" /> </form> </body> </html> If you could help then thanks sooo much!! Thanks in advanced if you can! Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/ Share on other sites More sharing options...
.josh Posted July 27, 2008 Share Posted July 27, 2008 assuming that that code is your index.php you need to actually echo out your message. You passed your message through the url via the GET method so you need to echo it out like so: echo $_GET['msg']; Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600936 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 It does that in the script... Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600937 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 Working script: http://jake.nukemcorp.net/cms/admin/ Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600941 Share on other sites More sharing options...
DeanWhitehouse Posted July 27, 2008 Share Posted July 27, 2008 For error checking echo out all your vars, and add error_reporting(E_ALL); to the top of the pages Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600944 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 Did that, dont know what its on about :-\ Notice: Undefined index: msg in /home/jakenuk/public_html/cms/admin/index.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600955 Share on other sites More sharing options...
DeanWhitehouse Posted July 27, 2008 Share Posted July 27, 2008 change if($_GET['msg'] != ""){ to if(isset($_GET['msg'])){ Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600956 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 Ok, changed, and i dont think i closed that curly bracked after that statement. Updated code: <?php error_reporting(E_ALL); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin</title> <link rel="stylesheet" href="style/css.css" /> </head> <body> <?php require_once "require/db.php"; if(isset($_GET['msg'])){ echo htmlentities($_GET['msg']); echo "<br />"; } mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $usrname = $_POST['usrname']; $pass = $_POST['pass']; if($usrname && $pass !== ""){ $usrname = stripslashes($usrname); $pass = stripslashes($pass); $usrname = mysql_real_escape_string($usrname); $pass = mysql_real_escape_string($pass); $pass = md5($pass); $sql="SELECT * FROM $db_name WHERE username='$usrname' and password='$pass'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ header("location:index2.php"); } else { header("location: index.php?msg=Incorrect Username or Password. Please try again."); } } ?> <form action="index.php" enctype="multipart/form-data" method="post"> <b>Username</b><br /> <input type="text" name="usrname" /><br /> <b>Password</b><br /> <input type="password" name="pass" /><br /> <input type="submit" value="Login" /> </form> </body> </html> New error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jakenuk/public_html/cms/admin/index.php on line 35 Warning: Cannot modify header information - headers already sent by (output started at /home/jakenuk/public_html/cms/admin/index.php:10) in /home/jakenuk/public_html/cms/admin/index.php on line 41 Can someone help?? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600958 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 Ok, i sorted it out, now it says: Warning: Cannot modify header information - headers already sent by (output started at /home/jakenuk/public_html/cms/admin/index.php:9) in /home/jakenuk/public_html/cms/admin/index.php on line 40 I know the headers should be at the top or something, any help?? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-600976 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 no one going to help? :'( Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-601002 Share on other sites More sharing options...
Nhoj Posted July 27, 2008 Share Posted July 27, 2008 You cannot use anything that modifies any headers after you have ANY output. For example: if($count==1){ header("location:index2.php"); } else { header("location: index.php?msg=Incorrect Username or Password. Please try again."); } cannot be used after ANYTHING has been outputted to the browser, INCLUDING <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin</title> <link rel="stylesheet" href="style/css.css" /> </head> <body> Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-601003 Share on other sites More sharing options...
Vivid Lust Posted July 27, 2008 Author Share Posted July 27, 2008 So anyway round this? Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-601004 Share on other sites More sharing options...
Nhoj Posted July 27, 2008 Share Posted July 27, 2008 Try the following: <?php error_reporting(E_ALL); require_once "require/db.php"; mysql_connect("$db_host", "$db_user", "$db_pass")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $usrname = $_POST['usrname']; $pass = $_POST['pass']; if($usrname && $pass !== ""){ $usrname = stripslashes($usrname); $pass = stripslashes($pass); $usrname = mysql_real_escape_string($usrname); $pass = mysql_real_escape_string($pass); $pass = md5($pass); $sql="SELECT * FROM $db_name WHERE username='$usrname' and password='$pass'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ header("location:index2.php"); } else { header("location: index.php?msg=Incorrect Username or Password. Please try again."); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Admin</title> <link rel="stylesheet" href="style/css.css" /> </head> <body> <? if(isset($_GET['msg'])){ echo htmlentities($_GET['msg']); echo "<br />"; } ?> <form action="index.php" enctype="multipart/form-data" method="post"> <b>Username</b><br /> <input type="text" name="usrname" /><br /> <b>Password</b><br /> <input type="password" name="pass" /><br /> <input type="submit" value="Login" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/116866-solved-login-not-working/#findComment-601005 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.