0% found this document useful (0 votes)
72 views

MODUL 5.2 CRUD DGN PHP OOP

This document discusses creating a CRUD (create, read, update, delete) application with PHP OOP (object-oriented programming) and MySQL. It includes: 1. Creating an index.php file to display existing records from a database table. 2. Creating an add.php file to allow adding new records via a form that inserts data into the table. 3. Using a Customers class to interact with the database and perform actions like displaying, inserting, and deleting records. The application allows viewing a list of records, adding new records via a form, and deleting or editing existing records directly from the list. PHP OOP principles are applied to manage the data access and CRUD functionality.

Uploaded by

Lavina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

MODUL 5.2 CRUD DGN PHP OOP

This document discusses creating a CRUD (create, read, update, delete) application with PHP OOP (object-oriented programming) and MySQL. It includes: 1. Creating an index.php file to display existing records from a database table. 2. Creating an add.php file to allow adding new records via a form that inserts data into the table. 3. Using a Customers class to interact with the database and perform actions like displaying, inserting, and deleting records. The application allows viewing a list of records, adding new records via a form, and deleting or editing existing records directly from the list. PHP OOP principles are applied to manage the data access and CRUD functionality.

Uploaded by

Lavina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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