Simple login script in PHP

This php script will accept two variables username and password from a html form, to validate whether it is a successful login or not

$username=$_POST[‘username’];
$password=$_POST[‘password’];
$database=’touring’;
$dbUserName=’root’;
$dbPassword=”;
mysql_connect(localhost, $dbUserName, $dbPassword);
@mysql_select_db($database) or die (“Unable to select the db”);
$query = “SELECT * FROM USER_INFO WHERE USER_NAME='”.$username.”‘”;
$result=mysql_query($query);
$rowCount = mysql_numrows($result);
if ($rowCount==0){
exit(‘Invalid user’);
}else{
$dbPass = mysql_result($result, 0, “password”);
if ($dbPass==$password){
echo ‘Success’;
}else{
exit(‘Invalid password’);
}
}
mysql_close();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s