sc00tz Posted February 3, 2010 Share Posted February 3, 2010 I have the following code set up on a login page for my website. When users register, the username, id, password, etc. are going into the table perfectly, but for some reason this part of the code is sending logins to login-failed.php. That leads me to believe it's coming from just this line: if(mysql_num_rows($result) == 1) { ...but I can't figure out why! Can anyone help me? Or should I move this to the PHP forum? Here's the code: $qry="SELECT * FROM users WHERE username='$username' AND password='".md5($_POST['password'])."'"; $result=mysql_query($qry); if($result) { if(mysql_num_rows($result) == 1) { session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_USER_NAME'] = $member['username']; $_SESSION['SESS_GENDER'] = $member['gender']; $_SESSION['SESS_AGE'] = $member['age']; session_write_close(); header("location: home.php"); exit(); }else { header("location: login-failed.php"); exit(); } }else { die("Query failed"); } Thanks Quote Link to comment https://forums.phpfreaks.com/topic/190760-login-failed-cant-figure-out-why/ Share on other sites More sharing options...
Illusion Posted February 3, 2010 Share Posted February 3, 2010 Do you debug your code? ..............even with simple echo statements. Quote Link to comment https://forums.phpfreaks.com/topic/190760-login-failed-cant-figure-out-why/#findComment-1006041 Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2010 Share Posted February 3, 2010 A) Take some responsibility for your code on your server with your database (we don't have access to these, so the only person here who can troubleshoot what is going on is you.) B) Echo the value being tested in the logic to see what it is to find out why the conditional test is failing. What does echoing mysql_num_rows($result) show? C) If mysql_num_rows($result) is zero, find out why. Echo $qry, then look directly in your database using your favorite database management program and check if there is a row that exactly matches the username and password value that is being put into the query. D) Does $username and $_POST['password'] have the correct values in them (for all we know, they don't, either because your form is invalid and is not sending anything or your logic that is for example setting $username is causing it to be empty...) Quote Link to comment https://forums.phpfreaks.com/topic/190760-login-failed-cant-figure-out-why/#findComment-1006052 Share on other sites More sharing options...
sc00tz Posted February 3, 2010 Author Share Posted February 3, 2010 Thanks for the help, I figured it out. Just a stupid mistake that I thought I had debugged but actually hadn't. SOLVED. Quote Link to comment https://forums.phpfreaks.com/topic/190760-login-failed-cant-figure-out-why/#findComment-1006304 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.