This post describes how to make login page with mysql. First we have to create table with the name of login. Then create two column with username and password. Then writes the code as below.if we give user name and password the code will check if there any matching record with this if it is it will go to home page.
first create table with username and password:
table name: login.
columns: username,password.
here the codes:
<?php
session_start();
if(isset($_POST['bttlogin']))
{
$con=mysql_connect('localhost','root','');
mysql_select_db('mini_project');
$username=$_POST['username'];
$password=$_POST['password'];
$result=mysql_query("select * from login where username='$username' and password='$password'");
if(mysql_num_rows($result)==1)
{
$_SESSION['username']=$username;
header('Location:view2.php');
}
else
echo 'account is invalid';
}
if(isset($_GET['logout']))
{
session_unregister('username');
}
?>
<form method="post">
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<td>user name</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="bttlogin" value="login"></td>
</tr>
</table>
</form>
first create table with username and password:
table name: login.
columns: username,password.
here the codes:
<?php
session_start();
if(isset($_POST['bttlogin']))
{
$con=mysql_connect('localhost','root','');
mysql_select_db('mini_project');
$username=$_POST['username'];
$password=$_POST['password'];
$result=mysql_query("select * from login where username='$username' and password='$password'");
if(mysql_num_rows($result)==1)
{
$_SESSION['username']=$username;
header('Location:view2.php');
}
else
echo 'account is invalid';
}
if(isset($_GET['logout']))
{
session_unregister('username');
}
?>
<form method="post">
<table cellpadding="2" cellspacing="2" border="1">
<tr>
<td>user name</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>password</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="bttlogin" value="login"></td>
</tr>
</table>
</form>