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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.