WT Practical 11


Practical : 11
Subject : Web Technology

Aim : Create login page and ask user to enter username and password and check that data from database if user name and password are correct then open welcome page form otherwise open registration form.


Source Code :
//login.php
<?php
$con = mysqli_connect("localhost","root","","login");
if(isset($_POST['btnsubmit']))
{
            $id=$_POST['txtname'];
            $pwd=$_POST['txtpwd'];
            $insqry="select id,pwd from login where id='".$id."' and pwd='".$pwd."'";
            $exec=mysqli_query($con,$insqry)or die(mysqli_error($con));
            if(mysqli_num_rows($exec)>0)
            {
                        header("Location:welcom(pra11-1).html");
            }
            else
            {
                        header("Location:registration(pra11-2).php");
            }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login form</title>
<style type="text/css">
.login {
height:210px;
width:190px;
border:1px #CCC solid;
padding:10px;
background-color: #ccffff;
}
.login input {
padding:5px;
margin:5px
}
</style>
</head>
<body>
<form method="post">
<div class="login">
<h1>LOGIN</h1>
<input type="text" placeholder="Username" name="txtname" required="">
<input type="password" placeholder="Password" name="txtpwd" required="">
<input type="submit" name="btnsubmit" value="Sign In">
</div>
</form>
</body>
</html>

//registration.php
<?php
$con = mysqli_connect("localhost","root","","login");
if(isset($_POST['btnsubmit']))
{
            $id=$_POST['txtname'];
            $pwd=$_POST['txtpwd'];
            $insqry="insert into login values('$id','$pwd')";
            $exec=mysqli_query($con,$insqry)or die(mysqli_error($con));
            if($exec)
            {
                        header("Location:welcom(pra11-1).html");
                        //echo '<script>alert("Submitted")</script>';
            }
            else
            {
                        header("Location:registration(pra11-2).php");
                        //echo '<script>alert("Record not Submitted")</script>';
            }
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Registration form</title>
<style type="text/css">
.login {
height:210px;
width:190px;
border:1px #CCC solid;
padding:10px;
background-color: #ccffff;
}
.login input {
padding:5px;
margin:5px
}
</style>
</head>
<body>
<form method="post">
<div class="login">
<h1>Registration</h1>
<input type="text" placeholder="Username" name="txtname" required="">
<input type="password" placeholder="Password" name="txtpwd" required="">
<input type="submit" name="btnsubmit" value="Sign In">
</div>
</form>
</body>
</html>

//welcome.html
<!DOCTYPE html>
<html>
<head>
            <title>Welcome</title>
</head>
<body>
<form action="login(pra11).php">
<h1>welcome</h1>
<input type="submit" value="Back to login">
</form>
</body>
</html>

Output :


Pratik Boghani

Author & Editor

Life is all about the next step.

0 comments:

Post a Comment