thminco Posted October 24, 2011 Share Posted October 24, 2011 Can someone please give me some ideas as to what might be wrong with this query...I keep getting no result and am echoing $count for debugging (and usernames and passwords) but get nothing for $count (expecting a 0 or a 1) or $dbusername or $dbpassword $sql="SELECT * FROM `users` WHERE `User name` = '$fusername' and `Password` = '$fpassword'"; $result=mysql_query($sql); $dbusername=mysql_result($result,0,"User name"); $dbpassword=mysql_result($result,0,"Password"); echo $dbusername; echo $dbpassword; // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $fusername and $fpassword, table row must be 1 row echo $fusername; echo $fpassword; echo $count; if($count==1){ (This is where I keep going to the else) Quote Link to comment https://forums.phpfreaks.com/topic/249669-help-with-sql-querygetting-no-results/ Share on other sites More sharing options...
Psycho Posted October 24, 2011 Share Posted October 24, 2011 Your query is failing - you need to add some error handling. Are you sure the field is name "User name"? I didn't think you could have spaces in a field name. Even if you can - it is bad practice. Besides you shouldn't be trying to extract the results before you have even checked if there were results. Lastly, only SELECT the fields you need - don't use "*" $query = "SELECT `User name`, `Password` FROM `users` WHERE `User name` = '$fusername' AND `Password` = '$fpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)) { echo "No results returned."; } else { $dbusername=mysql_result($result, 0, "User name"); $dbpassword=mysql_result($result, 0, "Password"); echo "Username: $dbusername<br>\n"; echo "Password: $dbpassword;<br>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/249669-help-with-sql-querygetting-no-results/#findComment-1281709 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.