LOGIN
Untuk membuat login kita akan melakukan 2 hal yaitu cek apakah username ada di dalam database lalu cek juga apakah password yang dimasukan sesuai tau tidak dengan yang ada pada database. Silhkan anda buat halaman login.php isikan code seperti dibawah :
<?php
require 'function.php';
if (isset($_POST["login"])) {
$username = $_POST["username"];
$password = $_POST["password"];
$result = mysqli_query($db, "SELECT * FROM user WHERE username = '$username' ");
// cek username
if (mysqli_num_rows($result) === 1) {
// cek pssword
$row = mysqli_fetch_assoc($result);
if (password_verify($password, $row["password"])) {
header("Location: index.php");
exit;
}
}
$error = true;
}
?>
<!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>Halaman Login</title>
</head>
<body>
<h1>LOGIN</h1>
<?php if (isset($error)) : ?>
<p style="color:red;">username / password salah</p>
<?php endif ?>
<form action="" method="POST">
<ul>
<li>
<label for="username">Username :</label>
<input type="text name" name="username" id="username">
</li>
<li>
<label for="password">Password :</label>
<input type="password" name="password" id="password">
</li>
<li>
<button type="submit" name="login"> Login</button>
</li>
</ul>
</form>
</body>
</html>





