hi all,
i have done simple login form with username=“admin” and password=“admin123”.
i am checking for sql injections.i have given “mysql_real_escape_string”
for both username and password fields.
but also it is not working…
if i give username as “admin --” and click the submit button(not giving password also) it is taking to the next page…
tell me whats wrong in my below code…
‘password’ is a reserved mySQL keyword. It won’t work. Change it to passwd or something other than password. I also think you’re overcomplicating the code. This is basically what I do.
$username=mysql_real_escape_string($_POST['txtuname']);
$password=mysql_real_escape_string($_POST['txtpwd']);
$result = mysql_query("SELECT * FROM log WHERE username='$username' AND passwd='$password'");
if(mysql_num_rows($result) > 0) {
// user checks out
} else {
// user doesn't check out
}
You shouldn’t have to check for DISTINCT because you should never have more than one instance of a username. Your username field should be UNIQUE so that each user gets a distinct username at signup. If you don’t do that you’re asking for trouble.