PRodgers4284 Posted February 21, 2008 Share Posted February 21, 2008 I have the following login script to check if a user has an active or active account but i cant same to get it to work, im not getting any errors but it just isnt doing the check for active or inactive users. Can anyone help? My code is <?php $validation = ""; /** * Checks whether or not the given username is in the * database, if so it checks if the given password is * the same password in the database for that user. * If the user doesn't exist or if the passwords don't * match up, it returns an error code (1 or 2). * On success it returns 0. */ function confirmUser($username, $password){ global $conn; /* Add slashes if necessary (for query) */ if(!get_magic_quotes_gpc()) { $username = addslashes($username); } /* Verify that user is in database */ $q = "select password from users where username = '$username'"; $result = mysql_query($q,$conn); if(!$result || (mysql_numrows($result) < 1)){ return 1; //Indicates username failure } /* Retrieve password from result, strip slashes */ $dbarray = mysql_fetch_array($result); $dbarray['password'] = stripslashes($dbarray['password']); $password = stripslashes($password); /* Validate that password is correct */ if($password == $dbarray['password']){ return 0; //Success! Username and password confirmed } else{ return 2; //Indicates password failure } $q = "select password,active from users where username = '$username'"; $sql = mysql_query($q); $row = mysql_fetch_array($sql); if($row['active']=='0'){ return 3; // inactive Account } else{ return 0; //Indicates success } Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 21, 2008 Share Posted February 21, 2008 You have an if/else block that returns from the function either way. Then, you are attempting to check to see whether or not the user is active. Your code never gets beyond the if/else statement because the function returns no matter what the result. Quote Link to comment Share on other sites More sharing options...
PRodgers4284 Posted February 21, 2008 Author Share Posted February 21, 2008 Hi thanks for the reply, if remove the else statement and use this: $q = "select password,active from users where username = '$username'"; $sql = mysql_query($q); $row = mysql_fetch_array($sql); if($row['active']=='0'){ return 3; //Success! Active Account } } Would this work? 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.