am i complete wrong here login prob

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

am i complete wrong here login prob

Post by nutstretch »

I ahve a form which the user enters username and password and pesses submit.

my php page then looks to see if there is a user with that username and password. it doesn't matter what password i use it lets me in each time.

Any ideas why this is.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$linkID = @mysql_connect("localhost", "root", "");
mysql_select_db("Customer", $linkID);
$resultID = mysql_query("SELECT * FROM tblLogon where UserName like '$username' AND Password like '$password'", $linkID);
if ($resultID == True)
{
print "$username, $password";
}
else
{
print "Your login failed sorry.<p>";
}
mysql_close($linkID);
?>

</body>
</html>

any help appreciated
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

Try this...

Code: Select all

<?php 

$linkID = @mysql_connect("localhost", "root", "");
mysql_select_db("Customer", $linkID);

$resultID = mysql_query("SELECT * FROM `tblLogon` where `UserName`='$username' AND `Password`='$password'", $linkID);

if(mysql_num_rows($resultID) > 0) 
{ 
print "$username, $password"; 
} 
else 
{ 
print "Your login failed sorry.<p>"; 
} 
mysql_close($linkID); 
?>
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

many thanks that works well. is this an efficient way of logging on to a database or is there a more efficeient way?
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post by Gen-ik »

It's ok to use as a basic log-in script... you could obviously always add more to it if you want/need to but it does the job :)
Post Reply