0% found this document useful (0 votes)
5 views

Lab4 Server Side Script Language for Dynamic Web Page

The document outlines a simple PHP-based login system consisting of an HTML form (index.php), a CSS stylesheet (style.css), a database connection script (dbconn.php), and a login processing script (login.php). The login form captures a username and password, validates the input, and checks against a database for authentication. If successful, it displays a success message; otherwise, it redirects back with an error message if the credentials are incorrect or missing.

Uploaded by

abdig017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lab4 Server Side Script Language for Dynamic Web Page

The document outlines a simple PHP-based login system consisting of an HTML form (index.php), a CSS stylesheet (style.css), a database connection script (dbconn.php), and a login processing script (login.php). The login form captures a username and password, validates the input, and checks against a database for authentication. If successful, it displays a success message; otherwise, it redirects back with an error message if the credentials are incorrect or missing.

Uploaded by

abdig017
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 4 server side script language for dynamic web page

Index.php
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<form action="login.php" method="POST">
<h1> Login form</h1>
<?php
if(isset($_GET['error'])){
?>
<p class = "error"><?php echo $_GET['error'];
?></p><?php
}
?>
<label>username</label><br>
<input type="text" name ="uname"><br>
<label>password</label><br>
<input type="password" name ="pname"><br>
<button type="submit">login</button>
</form>
</body>
</html>
Style.css
body{
background-color: #5f8b8d;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
form{
width: 500px;
border: 2px;
padding: 30px;
border-radius: 15px;
background-color: cornsilk;
}
input{
display: flex;
border: 2px;
width: 95%;
padding: 10px;
margin: 10px;
color: grey;
background-color: whitesmoke;
}
.error{
background-color: darkseagreen;
color: red;
padding: 10px;
width: 95%;
margin: 20px;
border-radius: 5px;
}
h1{
text-align: center;
margin-bottom: 40px;
}
button{
background-color: deepskyblue;
text-align: right;
color: #fff;
width: 15%;
padding: 10px;
border-radius: 5px;
margin-right: 10px;
border: none;
}
button:hover{
opacity: .7;
}
dbconn.php

<?php
$servername="localhost";
$username="root";
$password="";
$dbname="db_login";
$conn=mysqli_connect($servername, $username,$password,$dbname);
if(!$conn){
die("connection fail").mysqli_connect_error();
}
?>
LOGIN.PHP
<?php
include "dbconn.php";
if(isset($_POST['uname']) && isset($_POST['pname'])){
$uname = $_POST['uname'];
$pname = $_POST['pname'];
if(empty($uname)){
header("location: index.php?error= username is required");
exit();
}else if(empty($pname)){
header("location: index.php?error= password is required");
exit();
}else{
$sql = "SELECT * FROM `t_login` WHERE user_name='$uname' AND pass_word='$pname'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result)===1){
$row=mysqli_fetch_assoc($result);
if($row['user_name']===$uname && $row['pass_word']===$pname){
echo "<h1>login in successfull!</h1>";
}
}else{
header("location: index.php?error= username or password incorrect");
exit();
}}}

You might also like