Hi I am having problems creating a user login feature. I have created a form to allow users to create a username and password which then adds this information to mysql.
When i try to login it says:
no such login in the system. please try again.
The login name and password is correct so it has to be my process code which is:
- PHP: Select all
<?php
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'users';
$table = 'members';
$dbh=mysql_connect ("$host", "$user", "$pass") or die ('I cannot connect to the database because:' . mysql_error());
mysql_select_db ("$db");
$sql="SELECT Username FROM $table WHERE Username='".$Username."' and Password='".$Password."'";
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
print "successfully logged into system.";
}
?>
Can anyone help me with why it is not working, or is there a better way of doing it?
Thanks
Robert