Jump to content

Very Simple Login Code not working


Blekk

Recommended Posts

Hi, I used to do a bit of php, but stopped for ages, now I was trying to refresh my memory by creating a simple login. Here it is:

[code]$query = "SELECT * FROM te_users WHERE username='".mysql_real_escape_string($username)."','".md5($password)."'";
$result = mysql_query($query);
$rows = mysql_num_rows($result);
if($rows == 1)
{print"$username has logged in.";
}else{
print "Incorrect username or password";
}[/code]

I get the exception:

[quote]Warning: mysql_num_rows(): supplied argument is not a valid MySQL result...[/quote]

I remember using mysql_num_rows() last time I did this(a very long time ago lol), why will it not work now?

Thanks,

Any reply is appreciated.
Link to comment
https://forums.phpfreaks.com/topic/29328-very-simple-login-code-not-working/
Share on other sites

This means your query is failing, use a die() statement along with mysql_error() to handle some debugging, but I can tell you now, you dont specify a passwrd field.

Try something like...

[code=php:0]
$query = "SELECT * FROM te_users WHERE username='".mysql_real_escape_string($username)."' AND pass='".md5($password)."'";
$result = mysql_query($query) or die(mysql_error());
[/code]

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.