Tutorial Membuat Form Login dengan PHP dan MYSQL
Saturday, December 21, 2019
pertama anda siapkan dulu kode editor lalu
1. buat file index.php
2. buat file style.css
2. buat file koneksi.php
3. buat file login.php
index.php
<!DOCTYPE html>
<html>
<head>
<title>Halaman Login</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Halaman Login</h1>
<div class="form">
<form action="login.php" method="post" name="form_input">
<div class="username">
Username : <input type="text" name="username" placeholder="Masukan Username" required="">
</div>
<div class="password">
Password : <input type="text" name="password" placeholder="Masukan Password" required="">
</div>
<div class="tombol">
<input type="submit" name="input" value="LOGIN">
<input type="reset" name="reset" value="RESET">
</div>
</form>
</div>
</body>
</html>
style.css
h1{
margin-left:400px;
margin-top: 25px;
}
.form{
width: 500px;
height: 200px;
margin-top: 25px;
margin-left: 400px;
background-color: gray;
padding: 20px;
}
.username{
margin-top: 50px;
margin-bottom: 10px;
margin-left: 40px;
}
.username input{
width: 300px;
height: 25px;
}
.password{
margin-left: 43px;
margin-bottom: 20px;
}
.password input{
width: 300px;
height: 25px;
}
.tombol input{
width: 100px;
height: 25px;
margin-left: 110px;
background-color: lightblue;
}
koneksi.php
<?php
$koneksi = mysqli_connect('localhost', 'root', '', 'akademik');
if(!$koneksi){
echo "Koneksi Gagal";
}
?>
login.php
<?php
//untuk penghubung dengan file koneksi
include 'koneksi.php';
//cara menangkap data yang dikirim dari form
if(isset($_POST['input'])){
$username = $_POST['username'];
$password = $_POST['password'];
//ambil data dari database tabel login dengan username dan password yang sesuai
$data = mysqli_query($koneksi,"SELECT * FROM login WHERE username='$username' AND password='$password'");
if(mysqli_num_rows($data)){
echo "Login Berhasil";
}else{
echo "Login Gagal";
}
}
?>
Related Posts