ytmnd522 Posted June 9, 2006 Share Posted June 9, 2006 Hello guys.. Im having a hard time loging a user in. This is my script.. When I submit the data it just refreshes with no response if the user was found on da database or anything..what's up with my script. I have a mysql database named "mike" with a few records of users with passwords.thanks in advanced.[code]<? session_start()?><html><body><form action="vtcsignin.php" method="post">users:<INPUT type="text" name="user"><br>password:<INPUT type="password" name="password"><br><INPUT type="submit"></form></body></html><?if(isset($_POST['user']) && isset($_POST['pass'])){ if($logged_in_user == $user){ echo $_POST['user'] . " Your are already logged in"; exit; }}$db = mysql_connect("localhost","root") or die ("cant connect to database");mysql_select_db("mike", $db) or die("could not select database");$result = mysql_query("SELECT * FROM users WHERE userName = '".$user."' AND userPassword = PASSWORD('".$pass."')");if(!$result){ print "no information brought back";}if(mysql_num_rows($result) > 0){ $_SESSION['logged_in_user']=$user; echo "welcome, " . $user; exit;}elseif(mysql_num_rows($result)==0){ echo "No record found in the database"; session_destroy();}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11601-login-script/ Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 [code]if(mysql_num_rows($reuslt) > 0){[/code] shouldn't that be $result? Quote Link to comment https://forums.phpfreaks.com/topic/11601-login-script/#findComment-43831 Share on other sites More sharing options...
ytmnd522 Posted June 10, 2006 Author Share Posted June 10, 2006 yea i noticed that..and I thought that was the problem..but turns out it's not. BTW im running php 4.3.10 Quote Link to comment https://forums.phpfreaks.com/topic/11601-login-script/#findComment-43901 Share on other sites More sharing options...
legohead6 Posted June 10, 2006 Share Posted June 10, 2006 [!--quoteo(post=381998:date=Jun 9 2006, 01:50 PM:name=MikeyLopez)--][div class=\'quotetop\']QUOTE(MikeyLopez @ Jun 9 2006, 01:50 PM) [snapback]381998[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hello guys.. Im having a hard time loging a user in. This is my script.. When I submit the data it just refreshes with no response if the user was found on da database or anything..what's up with my script. I have a mysql database named "mike" with a few records of users with passwords.thanks in advanced.[code]<? session_start()?><html><body><form action="vtcsignin.php" method="post">users:<INPUT type="text" name="user"><br>password:<INPUT type="password" name="password"><br><INPUT type="submit"></form></body></html><?if(isset($_POST['user']) && isset($_POST['pass'])){ if($logged_in_user == $user){ echo $_POST['user'] . " Your are already logged in"; exit; }}$db = mysql_connect("localhost","root") or die ("cant connect to database");mysql_select_db("mike", $db) or die("could not select database");$result = mysql_query("SELECT * FROM users WHERE userName = '".$user."' AND userPassword = PASSWORD('".$pass."')");if(!$result){ print "no information brought back";}if(mysql_num_rows($result) > 0){ $_SESSION['logged_in_user']=$user; echo "welcome, " . $user; exit;}elseif(mysql_num_rows($result)==0){ echo "No record found in the database"; session_destroy();}?>[/code][/quote]I dont see where these two variables are set$logged_in_user$user Quote Link to comment https://forums.phpfreaks.com/topic/11601-login-script/#findComment-43910 Share on other sites More sharing options...
alpine Posted June 11, 2006 Share Posted June 11, 2006 You are relying on register globals to be ON here, and you are querying regardless of POST or not being set.AND you are checking for posted variable "pass" while your password textfield is named "password".Work your way with this one, i've not included a "is logged in"-check though.[code]<?session_start()if(isset($_POST['submitform'])){if(!empty($_POST['user']) || !empty($_POST['pass'])){$user = htmlspecialchars($_POST['user']);$pass = htmlspecialchars($_POST['pass']);$db = mysql_connect("localhost","root") or die ("cannot connect to database");mysql_select_db("mike", $db) or die("could not select database");$result = mysql_query("SELECT * FROM users WHERE userPassword = PASSWORD('$pass') AND userName = '$user'");if(mysql_num_rows($result) == "1"){$_SESSION['logged_in_user'] = $user;echo "welcome, " . $user;exit();}else{echo "No record found in the database";}}else{echo "Please fill out both username and password field..";}}echo <<<_HTML<form action = "vtcsignin.php" method = "post">users: <INPUT type = "text" name = "user"><br>password: <INPUT type = "password" name = "pass"><br><INPUT type = "submit" name = "submitform"></form>_HTML;?>[/code]You should also consider moving away from using PASSWORD in your query as it's not supported in newer mysql versions. Move to md5 or sha1 instead. Quote Link to comment https://forums.phpfreaks.com/topic/11601-login-script/#findComment-44208 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.