t.bo Posted July 17, 2006 Share Posted July 17, 2006 Hi all...I just tried my first code using sessions but there is something wrong. I always get "Your login is wrong" while I enter the correct username and pw. The username is correctly inputted though...Here is the code Login.htm:[code]<form action="login.php" method="post"><b>Username</b>:<input type="text" name="username" size="20"><br><b>Password</b>:<input type="password" name="pw" size="20"><br><input type="submit" value="Login"></form>[/code]Login.php:[code]<?phpsession_start();include('dbconnect.php');$username = $_GET[username];$pw = $_GET[pw];$q="SELECT * FROM `login` WHERE ((username='$username') AND (pw='$pw'))";$result= mysql_query($q) or die ("Could not execute query : $q." . mysql_error());if (mysql_num_rows($result) == 0){echo "<div align=center><b>Your login is wrong. Please click back and try again.</b></div>";}else{$r=mysql_fetch_array($result);$login_username=$r["username"];session_register("login_username");Header("Location: protected.php");}?>[/code]and finally protected.php[code]<?phpsession_start();if ($_SESSION["login_username"]=="") {Header("Location: login.htm");} else {echo "U r logged in...";}?>[/code]Hope someone can help me out...Grtz and thanks in advance Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/ Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 in your login.php, change the following 2 lines:$login_username=$r["username"];session_register("login_username");to$_SESSION['login_username'] = $r['username'];post again if it doesn't work. Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/#findComment-59263 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 SELECT * FROM login WHERE username='$username' AND pw='$pw';";try that Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/#findComment-59264 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 don't mind my previous post, I think the error is here:$q="SELECT * FROM `login` WHERE ((username='$username') AND (pw='$pw'))";change to:$q="SELECT * FROM `login` WHERE username='$username' and pw='$pw'"; Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/#findComment-59265 Share on other sites More sharing options...
brown2005 Posted July 17, 2006 Share Posted July 17, 2006 yeah i agree with hvle, even though i was first.. lol Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/#findComment-59266 Share on other sites More sharing options...
hvle Posted July 17, 2006 Share Posted July 17, 2006 lol, u beat me to it. >:( Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/#findComment-59272 Share on other sites More sharing options...
t.bo Posted July 17, 2006 Author Share Posted July 17, 2006 Thanks guys It works fine now. Link to comment https://forums.phpfreaks.com/topic/14830-session-login-system-does-not-work/#findComment-59343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.