DATABASE(TABLE):
SOURCE CODE (1 Folder, 5 Files):
<?php
$con = new mysqli('localhost', 'root', '', 'cruid_operation');
?>
(Isi dengan 'localhost', 'root', 'password phpmyadmin', 'nama_table') Jika kalian tidak set password untuk phpmyadmin kalian, maka bisa mengosongkannya seperti saya
DISPLAY.PHP:
<?php
include 'connect.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">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
<title>CRUID OPERATION</title>
</head>
<body>
<div class="container">
<button class="btn btn-primary my-5">
<a href="user.php" class="text-light ">Add User</a>
</button>
<table class="table">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone No</th>
<th scope="col">Password</th>
<th scope="col">Operations</th>
</tr>
</thead>
<tbody>
<?php
$sql="Select * from `cruid`";
$result=mysqli_query($con, $sql);
if($result){
while($row=mysqli_fetch_assoc($result)){
$id=$row['id'];
$name=$row['name'];
$email=$row['email'];
$mobile=$row['mobile'];
$password=$row['password'];
echo '<tr>
<th scope="row">'.$id.'</th>
<td>'.$name.'</td>
<td>'.$email.'</td>
<td>'.$mobile.'</td>
<td>'.$password.'</td>
<td>
<button class="btn btn-primary">
<a href="update.php?updateid='.$id.'" class="text-light">Update</a>
</button>
<button class="btn btn-danger">
<a href="delete.php?deleteid='.$id.'" class="text-light">Delete</a>
</button>
</td>
</tr>';
}
}
?>
</tbody>
</table>
</div>
</body>
</html>
<?php
include 'connect.php';
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$password = $_POST['password'];
$sql = "insert into `cruid` (name, email, mobile, password) values('$name', '$email', '$mobile', '$password')";
$result = mysqli_query($con, $sql);
if($result){
header('location:display.php');
// echo "Data inserted successfully";
}else{
die(mysqli_error($con));
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
<title>CRUID OPERATION</title>
</head>
<body>
<div class="container my-5">
<form method="post">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" placeholder="Enter your name" name="name" autocomplete="off">
</div>
<div class="form-group">
<label>Email</label>
<input type="text" class="form-control" placeholder="Enter your email" name="email" autocomplete="off">
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" class="form-control" placeholder="Enter your phone number" name="mobile"
autocomplete="off">
</div>
<div class="form-group">
<label>Password</label>
<input type="text" class="form-control" placeholder="Enter your password" name="password"
autocomplete="off">
</div>
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
</div>
</body>
</html>
UPDATE.PHP:
<?php
include 'connect.php';
$id=$_GET['updateid'];
$sql="Select * from `cruid` where id=$id";
$result=mysqli_query($con, $sql);
$row=mysqli_fetch_assoc($result);
$name=$row['name'];
$email=$row['email'];
$mobile=$row['mobile'];
$password=$row['password'];
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$password = $_POST['password'];
$sql = "update `cruid` set id=$id, name='$name', email='$email', mobile='$mobile', password='$password' where id=$id";
$result = mysqli_query($con, $sql);
if($result){
header('location:display.php');
// echo "Data inserted successfully";
}else{
die(mysqli_error($con));
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css">
<title>CRUID OPERATION</title>
</head>
<body>
<div class="container my-5">
<form method="post">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" placeholder="Enter your name" name="name" autocomplete="off"
value=<?php echo $name;?>>
</div>
<div class="form-group">
<label>Email</label>
<input type="text" class="form-control" placeholder="Enter your email" name="email"
autocomplete="off" value=<?php echo $email;?>>
</div>
<div class="form-group">
<label>Phone Number</label>
<input type="text" class="form-control" placeholder="Enter your phone number" name="mobile"
autocomplete="off" value=<?php echo $mobile;?>>
</div>
<div class="form-group">
<label>Password</label>
<input type="text" class="form-control" placeholder="Enter your password" name="password"
autocomplete="off" value=<?php echo $password;?>>
</div>
<button type="submit" class="btn btn-primary" name="submit">Update</button>
</form>
</div>
</body>
</html>
DELETE.PHP:
<?php
include 'connect.php';
if(isset($_GET['deleteid']));{
$id=$_GET['deleteid'];
$sql="delete from `cruid` where id=$id";
$result=mysqli_query($con, $sql);
if($result){
header ('location:display.php');
//echo "Deleted successfully";
}else{
die(mysqli_error($con));
}
}
?>
RUN PROGRAM
(Contoh Dashboard):
(Add User Form):
Before
(Update):
Result
Video Running: