Login a user using PHP & MySQL

January 3rd, 2011 by Nov Piseth Leave a reply »

Login user using php & mysql
This code is not yet completed but it is usable.

<?php
$user = $_POST['txtusername'];
$pass = $_POST['txtpassword'];
$login = $_POST['btnlogin'];

$dbhost = "localhost";
$dbuser = "iicuser";
$dbpass ="123456";
$dbname = "iicdatabase";

$cnn = mysql_connect($dbhost,$dbuser,$dbpass);
$sldb = mysql_select_db($dbname,$cnn);
if(isset($login)){
if(!$user){
echo "Please Input Your Username";
}
else{
$check_username = mysql_query("SELECT username FROM tbladmin WHERE username='".$user."'");
if(!mysql_num_rows($check_username)){
if(!$pass){
echo "Please Input Your Password";
}
else{
$check_password = mysql_query("SELECT password FROM tbladmin WHERE password='".$pass."'");
if(mysql_num_rows($check_password) && mysql_num_rows($check_username)){
echo "Well Done";
}
else{
echo "You might wrong username or password.";
}
}
}
}

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login with database</title>
</head>
<form action="#" method="post">
Username:<input type="text" name="txtusername" /><br />
Password:<input type="text" name="txtpassword" /><br />
<input type="submit" name="btnlogin" value="Login" />
</form>
<body>
</body>
</html>
Advertisement

Comments are closed.

WP Facebook Auto Publish Powered By : XYZScripts.com