Complete PHP CRUD
commit
ebe750c6c1
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
include '../config.php';
|
||||
|
||||
$id = $_POST['id'];
|
||||
$namabarang = $_POST['namabarang'];
|
||||
$jumlah = $_POST['jumlah'];
|
||||
|
||||
$id = mysqli_real_escape_string($conn, $id);
|
||||
$namabarang = mysqli_real_escape_string($conn, $namabarang);
|
||||
$jumlah = mysqli_real_escape_string($conn, $jumlah);
|
||||
|
||||
if(empty($namabarang) || empty($jumlah)) {
|
||||
header("Location: edit_data.php?id=$id");
|
||||
echo '<script>alert("Input data terlebih dahulu")</script>';
|
||||
} else {
|
||||
|
||||
$query = "UPDATE list_barang SET nama_barang='$namabarang',jumlah_stock='$jumlah' WHERE id='$id'";
|
||||
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
$cek = mysqli_num_rows($data);
|
||||
|
||||
if ($cek >= 0) {
|
||||
header("Location: dashboard.php");
|
||||
} else {
|
||||
echo '<script>alert("Edit data gagal")</script>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
include '../config.php';
|
||||
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$username = mysqli_real_escape_string($conn, $username);
|
||||
$password = mysqli_real_escape_string($conn, $password);
|
||||
|
||||
$query = "SELECT *
|
||||
FROM admin
|
||||
WHERE username = '$username' AND password = '$password'";
|
||||
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
$cek = mysqli_num_rows($data);
|
||||
|
||||
if ($cek > 0) {
|
||||
$_SESSION["username_admin"] = $username;
|
||||
$_SESSION["status_login_admin"] = "true";
|
||||
header("Location: dashboard.php");
|
||||
} else {
|
||||
header("Location: index.php?pesan=gagal");
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
include '../config.php';
|
||||
|
||||
$namabarang = $_POST['namabarang'];
|
||||
$jumlah_stok = $_POST['jumlah_stok'];
|
||||
|
||||
$namabarang = mysqli_real_escape_string($conn, $namabarang);
|
||||
$jumlah_stok = mysqli_real_escape_string($conn, $jumlah_stok);
|
||||
|
||||
if(empty($namabarang) || empty($jumlah_stok)) {
|
||||
header("Location: tambah_data.php");
|
||||
echo '<script>alert("Input data terlebih dahulu")</script>';
|
||||
} else {
|
||||
|
||||
$query = "INSERT INTO list_barang
|
||||
VALUES (
|
||||
'',
|
||||
'$namabarang',
|
||||
'$jumlah_stok'
|
||||
)";
|
||||
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
$cek = mysqli_num_rows ($data);
|
||||
|
||||
if ($cek >= 0) {
|
||||
echo '<script>alert("Input data berhasil")</script>';
|
||||
header("Location: dashboard.php");
|
||||
} else {
|
||||
echo '<script>alert("Input data gagal")</script>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_unset();
|
||||
session_start();
|
||||
|
||||
include('../config.php');
|
||||
|
||||
if($_SESSION["status_login_admin"] != "true") {
|
||||
header("Location: index.php?pesan=belum_login");
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM list_barang";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dashboard</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Welcome back <?php echo $_SESSION["username_admin"] ?></h1>
|
||||
<form action="logout.php" method="post" class="mb-3">
|
||||
<button type="submit" class="btn btn-primary">Logout</button>
|
||||
<a href="tambah_data.php" class="btn btn-secondary">Tambah Data</a>
|
||||
</form>
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th><?php echo 'ID Barang' ?></th>
|
||||
<th><?php echo 'Nama Barang' ?></th>
|
||||
<th><?php echo 'Jumlah Stock Barang' ?></th>
|
||||
<th><?php echo 'Update' ?></th>
|
||||
</tr>
|
||||
<?php
|
||||
while($row = mysqli_fetch_array($result)) {
|
||||
echo "<tr>";
|
||||
echo "<td>".$row['id']."</td>";
|
||||
echo "<td>".htmlspecialchars($row['nama_barang'], ENT_QUOTES)."</td>";
|
||||
echo "<td>".htmlspecialchars($row['jumlah_stock'], ENT_QUOTES)."</td>";
|
||||
echo "<td><a href='edit_data.php?id=$row[id]'>Edit</a> | <a href='delete_data.php?id=$row[id]'>Delete</a></td></tr>";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
include_once'../config.php';
|
||||
|
||||
$id = $_GET['id'];
|
||||
|
||||
$query = "DELETE FROM list_barang WHERE id='$id'";
|
||||
|
||||
mysqli_query($conn, $query);
|
||||
|
||||
header("Location: dashboard.php");
|
||||
?>
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Tambah Data</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
include'../config.php';
|
||||
|
||||
$id = $_GET['id'];
|
||||
$id = mysqli_real_escape_string($conn, $id);
|
||||
$query = "SELECT * FROM list_barang WHERE id='$id'";
|
||||
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
while ($row = mysqli_fetch_array($data)) {
|
||||
$id = $row['id'];
|
||||
$nama = $row['nama_barang'];
|
||||
$jumlah = $row['jumlah_stock'];
|
||||
}
|
||||
?>
|
||||
<div class="container">
|
||||
<h1 class="text-center my-5">Tambah Data</h1>
|
||||
<form action="cek_edit_data.php" method="post" align="center" class="my-5">
|
||||
<input type="hidden" name="id" value="<?php echo $id ?>">
|
||||
<div class="form-group">
|
||||
<label for="namabarang">Nama Barang: </label>
|
||||
<input class="form-control" type="namabarang" name="namabarang" maxlength="50" value="<?php echo htmlspecialchars($nama, ENT_QUOTES); ?>">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="jumlah">Jumlah Stock: </label>
|
||||
<input class="form-control" type="number" name="jumlah" maxlength="100" value="<?php echo htmlspecialchars($jumlah, ENT_QUOTES); ?>">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<br>
|
||||
<a href="dashboard.php">Go Back to Dashboard</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Login admin</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if (isset($_GET['pesan'])) {
|
||||
if ($_GET['pesan'] == 'gagal') {
|
||||
echo '<script>alert("Login gagal, cek ulang username / password")</script>';
|
||||
} else if ($_GET['pesan'] == 'logout') {
|
||||
echo '<script>alert("Berhasil logout")</script>';
|
||||
} else if ($_GET['pesan'] == 'belum_login') {
|
||||
echo '<script>alert("Silahkan login terlebih dahulu")</script>';
|
||||
} // Muhammad Daffa ~ daffa.tech
|
||||
}
|
||||
?>
|
||||
<div class="container">
|
||||
<h1 class="text-center my-5">Login Admin</h1>
|
||||
<!-- <img src="images/gudang.jpg" class="img-fluid rounded mx-auto d-block"> -->
|
||||
<form action="cek_login.php" method="post" align="center" class="my-5">
|
||||
<div class="form-group">
|
||||
<label for="username">Username: </label>
|
||||
<input class="form-control" type="username" name="username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password: </label>
|
||||
<input class="form-control" type="password" name="password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<br>
|
||||
<a href="../index.php">Go back to homepage</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
session_unset();
|
||||
|
||||
session_destroy();
|
||||
|
||||
header("Location: index.php?pesan=logout")
|
||||
?>
|
|
@ -0,0 +1,41 @@
|
|||
<!-- Muhammad Daffa ~ daffa.tech-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Tambah Data</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- <?php
|
||||
if (isset($_GET['pesan'])) {
|
||||
if ($_GET['pesan'] == 'password_false') {
|
||||
echo '<script>alert("Password tidak sama dengan konfirmasi password")</script>';
|
||||
} else if ($_GET['pesan'] == 'empty_form') {
|
||||
echo '<script>alert("Isi semua form yang tertera")</script>';
|
||||
} else if ($_GET['pesan'] == 'register_gagal') {
|
||||
echo '<script>alert("Register gagal")</script>';
|
||||
}
|
||||
}
|
||||
?> -->
|
||||
<div class="container">
|
||||
<h1 class="text-center my-5">Tambah Data</h1>
|
||||
<!-- <img src="images/gudang.jpg" class="img-fluid rounded mx-auto d-block"> -->
|
||||
<form action="cek_tambah_data.php" method="post" align="center" class="my-5">
|
||||
<div class="form-group">
|
||||
<label for="namabarang">Nama Barang: </label>
|
||||
<input class="form-control" type="namabarang" name="namabarang">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="jumlah_stok">Jumlah Stock: </label>
|
||||
<input class="form-control" type="number" name="jumlah_stok">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<br>
|
||||
<a href="dashboard.php">Go Back to Dashboard</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
$servername = "localhost";
|
||||
$username = "root";
|
||||
$password = "";
|
||||
$databasename = "miniproyek";
|
||||
|
||||
// Create connection
|
||||
$conn = mysqli_connect($servername, $username, $password, $databasename);
|
||||
|
||||
// Check connection
|
||||
if (!$conn) {
|
||||
die("Connection failed");
|
||||
}
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
?>
|
|
@ -0,0 +1,54 @@
|
|||
<!-- Muhammad Daffa ~ daffa.tech-->
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Complete PHP CRUD</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="author" content="Muhammad Daffa">
|
||||
<meta name="description" content="Complete PHP CRUD">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
<style type="text/css">
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
background-image: url("https://images3.alphacoders.com/988/thumb-1920-988316.jpg");
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
.mid-center {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-size: 4em;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: center;
|
||||
margin-top: 250px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="position-relative h-100">
|
||||
<div class="position-absolute mid-center">
|
||||
<h1>Muhammad Daffa</h1>
|
||||
<a href="admin" class="btn btn-secondary btn-lg btn-block">Admin Login</a>
|
||||
<a href="user" class="btn btn-secondary btn-lg btn-block">User Login</a>
|
||||
<footer>
|
||||
© Copyright 2020 Muhammad Daffa ~ daffa.tech
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,134 @@
|
|||
-- phpMyAdmin SQL Dump
|
||||
-- Muhammad Daffa ~ daffa.tech
|
||||
-- version 5.0.3
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: 127.0.0.1
|
||||
-- Generation Time: Oct 25, 2020 at 04:25 AM
|
||||
-- Server version: 10.4.14-MariaDB
|
||||
-- PHP Version: 7.4.11
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Database: `miniproyek`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `admin`
|
||||
--
|
||||
|
||||
CREATE TABLE `admin` (
|
||||
`id` int(11) NOT NULL,
|
||||
`username` varchar(50) NOT NULL,
|
||||
`email` varchar(50) NOT NULL,
|
||||
`password` varchar(50) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
--
|
||||
-- Dumping data for table `admin`
|
||||
--
|
||||
|
||||
INSERT INTO `admin` (`id`, `username`, `email`, `password`) VALUES
|
||||
(1, 'admin', 'admin@gmail.com', 'admin'),
|
||||
(2, 'admin2', 'admin2@gmail.com', 'admin2');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `list_barang`
|
||||
--
|
||||
|
||||
CREATE TABLE `list_barang` (
|
||||
`id` int(11) NOT NULL,
|
||||
`nama_barang` varchar(255) NOT NULL,
|
||||
`jumlah_stock` varchar(500) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
--
|
||||
-- Dumping data for table `list_barang`
|
||||
--
|
||||
|
||||
INSERT INTO `list_barang` (`id`, `nama_barang`, `jumlah_stock`) VALUES
|
||||
(25, 'Test', '100');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `user`
|
||||
--
|
||||
|
||||
CREATE TABLE `user` (
|
||||
`id` int(11) NOT NULL,
|
||||
`fullname` varchar(255) NOT NULL,
|
||||
`username` varchar(100) NOT NULL,
|
||||
`telephone_number` varchar(255) NOT NULL,
|
||||
`email` varchar(255) NOT NULL,
|
||||
`password` varchar(255) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
--
|
||||
-- Dumping data for table `user`
|
||||
--
|
||||
|
||||
INSERT INTO `user` (`id`, `fullname`, `username`, `telephone_number`, `email`, `password`) VALUES
|
||||
(1, 'Daffa Daffa', 'user', '085111111111', 'user@gmail.com', '12345');
|
||||
|
||||
--
|
||||
-- Indexes for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- Indexes for table `admin`
|
||||
--
|
||||
ALTER TABLE `admin`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `list_barang`
|
||||
--
|
||||
ALTER TABLE `list_barang`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indexes for table `user`
|
||||
--
|
||||
ALTER TABLE `user`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for dumped tables
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `admin`
|
||||
--
|
||||
ALTER TABLE `admin`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `list_barang`
|
||||
--
|
||||
ALTER TABLE `list_barang`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=27;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT for table `user`
|
||||
--
|
||||
ALTER TABLE `user`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=14;
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
session_start();
|
||||
|
||||
include '../config.php';
|
||||
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$username = mysqli_real_escape_string($conn, $username);
|
||||
$password = mysqli_real_escape_string($conn, $password);
|
||||
|
||||
$query = "SELECT *
|
||||
FROM user
|
||||
WHERE username = '$username' AND password = '$password'";
|
||||
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
$cek = mysqli_num_rows($data);
|
||||
|
||||
if ($cek > 0) {
|
||||
$_SESSION["username_user"] = $username;
|
||||
$_SESSION["status_login_user"] = "true";
|
||||
header("Location: dashboard.php");
|
||||
} else {
|
||||
header("Location: index.php?pesan=gagal");
|
||||
}
|
||||
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
?>
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
include '../config.php';
|
||||
|
||||
$name = $_POST['name'];
|
||||
$username = $_POST['username'];
|
||||
$no_telp = $_POST['no_telp'];
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
$password_confirm = $_POST['password_confirm'];
|
||||
|
||||
$name = mysqli_real_escape_string($conn, $name);
|
||||
$username = mysqli_real_escape_string($conn, $username);
|
||||
$no_telp = mysqli_real_escape_string($conn, $no_telp);
|
||||
$email = mysqli_real_escape_string($conn, $email);
|
||||
$password = mysqli_real_escape_string($conn, $password);
|
||||
$password_confirm = mysqli_real_escape_string($conn, $password_confirm);
|
||||
|
||||
if ($password != $password_confirm) {
|
||||
header("Location: register.php?pesan=password_false");
|
||||
} elseif (empty($name) || empty($username) || empty($no_telp) || empty($email)) {
|
||||
header("Location: register.php?pesan=empty_form");
|
||||
} else {
|
||||
$query = "INSERT INTO user (id, fullname, username, telephone_number, email, password)
|
||||
VALUES (
|
||||
'',
|
||||
'$name',
|
||||
'$username',
|
||||
'$no_telp',
|
||||
'$email',
|
||||
'$password'
|
||||
)";
|
||||
|
||||
$data = mysqli_query($conn, $query);
|
||||
|
||||
$cek = mysqli_num_rows($data);
|
||||
|
||||
if ($cek >= 0) {
|
||||
header("Location: index.php?pesan=register_berhasil");
|
||||
} else {
|
||||
header("Location: register.php?pesan=register_gagal");
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_unset();
|
||||
session_start();
|
||||
|
||||
include('../config.php');
|
||||
|
||||
if($_SESSION["status_login_user"] != "true") {
|
||||
header("Location: index.php?pesan=belum_login");
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM list_barang";
|
||||
$result = mysqli_query($conn, $sql);
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dashboard</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Welcome back <?php echo htmlspecialchars($_SESSION["username_user"], ENT_QUOTES) ?></h1>
|
||||
<form action="logout.php" method="post" class="mb-3">
|
||||
<button type="submit" class="btn btn-primary">Logout</button>
|
||||
</form>
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<th><?php echo 'ID Barang' ?></th>
|
||||
<th><?php echo 'Nama Barang' ?></th>
|
||||
<th><?php echo 'Jumlah Stock Barang' ?></th>
|
||||
</tr>
|
||||
<?php
|
||||
while($row = mysqli_fetch_array($result)) {
|
||||
echo "<tr>";
|
||||
echo "<td>".$row['id']."</td>";
|
||||
echo "<td>".htmlspecialchars($row['nama_barang'], ENT_QUOTES)."</td>";
|
||||
echo "<td>".htmlspecialchars($row['jumlah_stock'], ENT_QUOTES)."</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,45 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Login user</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if (isset($_GET['pesan'])) {
|
||||
if ($_GET['pesan'] == 'gagal') {
|
||||
echo '<script>alert("Login gagal, cek ulang username / password")</script>';
|
||||
} else if ($_GET['pesan'] == 'logout') {
|
||||
echo '<script>alert("Berhasil logout")</script>';
|
||||
} else if ($_GET['pesan'] == 'belum_login') {
|
||||
echo '<script>alert("Silahkan login terlebih dahulu")</script>';
|
||||
} else if ($_GET['pesan'] == 'register_berhasil') {
|
||||
echo '<script>alert("Register berhasil!")</script>';;
|
||||
}
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
}
|
||||
?>
|
||||
<div class="container">
|
||||
<h1 class="text-center my-5">Login User</h1>
|
||||
<!-- <img src="images/gudang.jpg" class="img-fluid rounded mx-auto d-block"> -->
|
||||
<form action="cek_login.php" method="post" align="center" class="my-5">
|
||||
<div class="form-group">
|
||||
<label for="username">Username: </label>
|
||||
<input class="form-control" type="username" name="username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password: </label>
|
||||
<input class="form-control" type="password" name="password">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<br>
|
||||
<a href="register.php">Register in here</a>
|
||||
<br>
|
||||
<a href="../index.php">Go back to homepage</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
// Muhammad Daffa ~ daffa.tech
|
||||
session_start();
|
||||
|
||||
session_unset();
|
||||
|
||||
session_destroy();
|
||||
|
||||
header("Location: index.php?pesan=logout")
|
||||
?>
|
|
@ -0,0 +1,56 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Register user</title>
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
if (isset($_GET['pesan'])) {
|
||||
if ($_GET['pesan'] == 'password_false') {
|
||||
echo '<script>alert("Password tidak sama dengan konfirmasi password")</script>';
|
||||
} else if ($_GET['pesan'] == 'empty_form') {
|
||||
echo '<script>alert("Isi semua form yang tertera")</script>';
|
||||
} else if ($_GET['pesan'] == 'register_gagal') {
|
||||
echo '<script>alert("Register gagal")</script>';
|
||||
} // Muhammad Daffa ~ daffa.tech
|
||||
}
|
||||
?>
|
||||
<div class="container">
|
||||
<h1 class="text-center my-5">Register User</h1>
|
||||
<!-- <img src="images/gudang.jpg" class="img-fluid rounded mx-auto d-block"> -->
|
||||
<form action="cek_register.php" method="post" align="center" class="my-5">
|
||||
<div class="form-group">
|
||||
<label for="name">Nama Lengkap: </label>
|
||||
<input class="form-control" type="name" name="name">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="username">Username: </label>
|
||||
<input class="form-control" type="username" name="username">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="no_telp">Nomor Telepon: </label>
|
||||
<input class="form-control" type="number" name="no_telp">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email: </label>
|
||||
<input class="form-control" type="email" name="email">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password">Password: </label>
|
||||
<input class="form-control" type="password" name="password">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="password_confirm">Password Confirmation: </label>
|
||||
<input class="form-control" type="password" name="password_confirm">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<br>
|
||||
<a href="index.php">Go Back to Login Page</a>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue