View Single Post
  #1 (permalink)  
Old Mar 28th, 2007, 14:50
robukni robukni is offline
Up'n'Coming Member
Join Date: Jan 2006
Location: NI
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Username & Password

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

Last edited by karinne; Mar 28th, 2007 at 14:53. Reason: Please use [php]...[/php] tags when displaying PHP code!
Reply With Quote