Step-1: Copy this bellow code in to notepad and save it as "index.php".
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="login.php" method="post">
<input type="text" name="uname" /><br />
<input type="password" name="pass" /><br />
<input type="submit" value="Login" />
</form>
</body>
</html>
Step-2: Copy this bellow code and save it as "login.php".
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
$uname=$_POST["uname"];
$pass=$_POST["pass"];
//print "$name $pass";
$con=mysql_connect("localhost","root","");
if(!$con){
die("Database could not connect: " .mysql_error());
}
mysql_select_db("userinfo",$con);
$sql= "SELECT * FROM `login` WHERE username='$uname' and password='$pass'";
$result=mysql_query($sql);
$n=mysql_num_rows($result);
if($n==0){
print "You did not registered yet!";
}else{
print "Login successful!";
}
?>
</body>
</html>
Step-3: If you use xampp then above two newly created php files save in a folder named "login"(if you want) and copy the folder and past it in your local host root folder name "htdocks". And if you use wampp then past it in to "www" folder. That's it.
Step-4: Create Database
Go to the localhost from browser and then go php myadmin. You will find this pictures bellow. Just follow and create your database and table according to my picture.
1. You are in localhost
2. Type "userinfo"
3. Click "Create"

"userinfo" database created. Now:
1. Type "login"
2. type "2"
3. click "Go"

Fill up the form according to picture bellow and click "save"

You will find a "login" table created under "userinfo" database in left side. Click on "login" from left side and you will see this picture bellow. Fill up it according to picture and click the second "Go" button.

After clicking "Go" button you will see the bellow picture.

Click the "login" and you are done.
No comments:
Post a Comment