wrathican Posted April 20, 2008 Share Posted April 20, 2008 hey guys im making a login script that does the following in this order: 1 checks to see if the username exsists 2 if the username exists, get the password from the db 3 compare the db pass and entered pass 4 if they match check to see if the account is activated a if the account isnt activated it returns to some page with an error b if the account is active it logs the person in using sessions login script: <?php $username = $_POST['username']; $password = $_POST['password']; $password = sha1($password); $query = "SELECT user_username, user_password, user_level, user_active FROM ls12_users WHERE user_username='".$username."'"; $result = query($query); $rows = numRows($result); if($rows == 1) { $array = fetchArray($result); $username = $array['user_username']; $dbpassword = $array['user_password']; $level = $array['user_level']; $active = $array['user_active']; if ($password == $dbpassword) { //check if active if ($active == 1) { //the account is active. set sessions $_SESSION['username'] = $username; $_SESSION['level'] = $level; header('location: ../index.php'); }else{ //account is not active $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but your account has not been activated yet. Please check your email for the activation email and follow the instructions there."; $_SESSION['errormessage'] = $errorarray; header('location: ../login.php'); } }else{ $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but the password you entered was incorrect. Please try again."; $_SESSION['errormessage'] = $errorarray; header('location: ../login.php'); } }else{ $_SESSION['errorstate'] = 1; $errorarray[] = "Sorry, but the username you entered does not exsist. Please try again."; $_SESSION['errormessage'] = $errorarray; header('location: ../login.php'); } ?> functions.inc: <?php //queries the db function query($query) { mysql_query($query); } //gets an array based on the query function fetchArray($result) { mysql_fetch_array($result); } //get the number of rows from the query function numRows($result) { mysql_num_rows($result); } ?> i get this error "Sorry, but the username you entered does not exsist. Please try again." whihch means that the username i entered doesnt exsist in the db. however the username DOES actually exsist, any ideas why i am getting this error? Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted April 20, 2008 Share Posted April 20, 2008 their is three lines that you may need to change, change your SQL to this: $query = "SELECT `user_username`, `user_password`, `user_level`, `user_active` FROM l`s12_users` WHERE `user_username` = '".$username."'"; and change $row to: $rows = mysql_num_rows($result); and finally, change $array to: $array = mysql_fetch_array($result); Quote Link to comment Share on other sites More sharing options...
dptr1988 Posted April 20, 2008 Share Posted April 20, 2008 Your db functions are not returning the results. Example: <?php // Your function function query($query) { mysql_query($query); } //Should be function query($query) { return mysql_query($query); } ?> Quote Link to comment Share on other sites More sharing options...
wrathican Posted April 20, 2008 Author Share Posted April 20, 2008 ahh, damit, i cant beleive i forgot to put return in... ive been coding all day... so that's my excuse! Thanks for the replies both of you! Quote Link to comment Share on other sites More sharing options...
GameYin Posted April 20, 2008 Share Posted April 20, 2008 You have 2 $password's Quote Link to comment 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.