Jul 13, 2024
htdocs
(contoh: V10
).former
, regita
, dashboard
.localhost/V10
.phpmyadmin
di localhost/phpmyadmin
.user
atau db_users
.users
dengan kolom-kolom menggunakan tipe VARCHAR
dan Primary Key
.index.html
, style.html
, dashboard.html
.koneksi.php
:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db_users";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
localhost/V10/koneksi.php
untuk tes koneksi.registrasi.php
contoh:
<?php
require 'koneksi.php';
$fullname = $_POST['fullname'];
$username = $_POST['username'];
$institution = $_POST['institution'];
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "INSERT INTO users (fullname, username, institution, email, password) VALUES ('$fullname', '$username', '$institution', '$email', '$password')";
if ($conn->query($sql) === TRUE) {
header("Location: index.html");
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
registrasi.html
dengan registrasi.php
via form action.login.php
contoh:
<?php
require 'koneksi.php';
$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header("Location: dashboard.html");
} else {
echo "Email atau password anda salah. Silakan coba lagi.";
}
$conn->close();
?>
index.html
dengan login.php
via form action.