You are on page 1of 6

MODUL 5.

CRUD dengan PHP OOP

a) Membuat file index.php


<?php
include 'customers.php';
$customerObj = new Customers();

?>

<!DOCTYPE hmtl>
<html lang = "eng">
<head>
<title> CRUD Data dengan PHP OOP dan MySQL</title>
<meta charset = "utf=8"/>
<meta name="viewport" content="width=device-widht, initial-
scale=1"/>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.cs
s"/>
<link rel="stylesheet"
href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"/>
</head>
<body>
<div class="card text-center" style="padding:15px;">
<h4> CRUD Data dengan PHP OOP dan MySQL </h4>
</div><br/><br/>

<?php
if (isset($_GET['msg1']) == "insert") {
echo "<div class = 'alert alert-succes alert-dismissible'> <button
type='button' class='close' data-dismiss='alert'>&times;</button> Your
Registration added succesfully</div>";
}
?>
<h2> View records<a href="add.php" class="btn btn-primary"
style="float:right;"> Add New Record</a></h2>
<table class="table table-hover">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Username</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$customers = $customerObj->displayData();
foreach ($customers as $customer){
?>
<tr>
<td><?php echo $customer['id']?></td>
<td><?php echo $customer['name']?></td>
<td><?php echo $customer['email']?></td>
<td><?php echo $customer['username']?></td>
<td>
<a href="edit.php?editId=<?php echo $customer['id']?>"
style="color:green">
<i class ="fa fa-pencil" aria-hidden="true"></i></a>
&nbsp
<a href="index.php?deleteId=<?php echo
$customer['id']?>"
style="color:red" onclick="confirm('Are you sure want
to delete this record')">
<i class="fa fa-trash" aria-hidden="true"></i>
</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></s
cript>
<script
src="https://maxcdn.bootsrapcdn.com/bootsrap/4.5.2/js/bootstrap.min.js"></
script>
</body>
</html>
b) Membuat file add.php
<?php
include 'customers.php';
$customerObj = new Customers();

if(isset($_POST['submit'])) {
$customerObj->insertData($_POST);
}
?>

<!DOCTYPE hmtl>
<html lang = "eng">
<head>
<title> CRUD Data dengan PHP OOP dan MySQL</title>
<meta charset = "utf=8"/>
<meta name="viewport" content="width=device-widht, initial-
scale=1"/>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.cs
s"/>
<link rel="stylesheet"
href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css"/>
</head>
<body>
<div class="card text-center" style="padding:15px;">
<h4> CRUD Data dengan PHP OOP dan MySQL </h4>
</div><br/>

<div class="container">
<form action="add.php" method="POST">
<div class="form-group">
<label for = "name">Name :</label>
<input type="text" class="form-control" name="name"
placeholder="Enter name" required=""/>
</div>
<div class="form-group">
<label for = "email">Email address :</label>
<input type="email" class="form-control" name="email"
placeholder="Enter email" required=""/>
</div>
<div class="form-group">
<label for = "username">Username :</label>
<input type="text" class="form-control"
name="username" placeholder="Enter username" required=""/>
</div>
<div class="form-group">
<label for = "password">Password :</label>
<input type="password" class="form-control"
name="password" placeholder="Enter password" required=""/>
</div>
<input type="submit" name="submit" class="btn btn-primary"
style="float:right;" value="Submit"/>
</form>
</div>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></s
cript>
<script
src="https://maxcdn.bootsrapcdn.com/bootsrap/4.5.2/js/bootstrap.min.js"></
script>
</body>
</html>

1. Menampilkan Halaman Web pada Browser


a) Membuka halaman crud_oop
b) Membuka Halaman Input

c) Mencoba Menambahkan Data

d) Data Masuk kedalam Record

You might also like