Lab #4

USER DATA INPUT THROUGH FORMS

1. Create login page in PHP

index.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login page</title>

<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.user-img img{
border-radius: 100%;
max-width: 150px;
width: 50%;
}

.wrapper{
max-width: 400px;
width: 100%;
margin: 0 auto;
text-align: center;
margin-top: 50px;
}

input{
box-sizing: border-box;
width: 100%;
padding: 10px;
margin: 5px 0;
border:none;
background-color: #f1f1f1;
}

button{
width: 100%;
padding: 10px;
margin: 5px 0;
background-color: #2196F3;
color: #fff;
border:none;
}

button:hover{
background-color: #0e84e3;
}
.success-text{
text-align: center;
margin-top: 10px;
color:green;
}
</style>
</head>
<body>
<div class="wrapper">
<form action="" method="post">
<div class="user-img">
<img src="https://iconape.com/wp-content/png_logo_vector/user-circle.png" alt="user logo" >
</div>

<div>
<input type="text" placeholder="Enter username" name="name" required>
</div>
<div>
<input type="password" placeholder="Enter password" name="password" required>
</div>

<div>
<button type="submit">Login</button>
</div>
</form>
</div>
</body>
</html>

<?php
if($_POST['name'] == 'admin' && $_POST['password'] == 'admin123'){
echo "<p class='success-text'>Login successfully</p>";
}
?>

Output

Login form in PHP


Happy coding :)