Jump to content

HELP with sql query...getting no results


thminco

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/249669-help-with-sql-querygetting-no-results/
Share on other sites

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.