U need o create 3 files.
1. In Config.php file you initialize your database.(localhost/phpmyadmin)
2. In Login.php file your login script.
3. Finally in Result.php file your output result.
//name the file Config.php
<?php
$uname = 'root';
$pass = ''; //by default password is null or empty
//connection info
if (!($conn=mysql_connect($host, $uname, $pass))) {
printf("error connecting to DB by user = $uname and pwd=$pass");
exit;
}
$db=mysql_select_db($dbname,$conn) or die("Unable to connect to
database1");
?>
// Login.php file
<?php
<form action="result.php" method="post">
<body>
<label><b>LOGIN :</b></label></br>
<label style="display: block; float: left; width: 100px">NAME :</label><input type="text" name="username"/><br>
<label style="display: block; float: left; width: 100px">PASSWORD :</label><input type="password" name="password"/></br>
<input type="submit" value="LOGIN"/></br>
</body>
?>
// Result.php file
<?php
include('config.php');
$username = $_REQUEST['username'];
$password =$_REQUEST['password'];
$sql=mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'");
$row=mysql_num_rows($sql);//for checking if required username and password is correct or not
if($row>0)
{
echo "LOGIN SUCCESSFUL";
}
else
{
echo "FAILED";
}
?>
1. In Config.php file you initialize your database.(localhost/phpmyadmin)
2. In Login.php file your login script.
3. Finally in Result.php file your output result.
//name the file Config.php
<?php
$host = 'localhost';
$dbname = 'user';
$uname = 'root';
$pass = ''; //by default password is null or empty
//connection info
if (!($conn=mysql_connect($host, $uname, $pass))) {
printf("error connecting to DB by user = $uname and pwd=$pass");
exit;
}
$db=mysql_select_db($dbname,$conn) or die("Unable to connect to
database1");
?>
// Login.php file
<?php
<form action="result.php" method="post">
<body>
<label><b>LOGIN :</b></label></br>
<label style="display: block; float: left; width: 100px">NAME :</label><input type="text" name="username"/><br>
<label style="display: block; float: left; width: 100px">PASSWORD :</label><input type="password" name="password"/></br>
<input type="submit" value="LOGIN"/></br>
</body>
</form>
?>
// Result.php file
<?php
include('config.php');
$username = $_REQUEST['username'];
$password =$_REQUEST['password'];
$sql=mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'");
$row=mysql_num_rows($sql);//for checking if required username and password is correct or not
if($row>0)
{
echo "LOGIN SUCCESSFUL";
}
else
{
echo "FAILED";
}
?>
No comments:
Post a Comment