Rachmat Ramadhan-183112706450047-TUGAS 7
Rachmat Ramadhan-183112706450047-TUGAS 7
Latihan CRUD
Buatlah CRUD sederhana menggunakan PHP dan MySQL dengan langkah-langkah sebagai berikut:
1. Membuat Database.sql
2. Membuat file config.php
3. Membuat file index.php
4. Membuat file add.php
5. Membuat file edit.php
6. Membuat file delete.php
<?php
/**
* using mysqli_connect for database connection
*/
$databaseHost = 'localhost';
$databaseName = 'crud_db';
$databaseUsername = 'root';
$databasePassword = '';
?>
<?php
// Create database connection using config file
include_once("config.php");
<html>
<head>
<title>Homepage</title>
</head>
<body>
<a href="add.php">Add New User</a><br/><br/>
<tr>
<th>Name</th> <th>Mobile</th> <th>Email</th> <th>Update</th>
</tr>
<?php
while($user_data = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$user_data['name']."</td>";
echo "<td>".$user_data['mobile']."</td>";
echo "<td>".$user_data['email']."</td>";
echo "<td><a href='edit.php?id=$user_data[id]'>Edit</a> | <a
href='delete.php?id=$user_data[id]'>Delete</a></td></tr>";
}
?>
</table>
</body>
</html>
Tampilkan tangkapan layar index.php
<html>
<head>
<title>Add Users</title>
</head>
<body>
<a href="index.php">Go to Home</a>
<br/><br/>
<?php
<?php
// include database connection file
include_once("config.php");
$name=$_POST['name'];
$mobile=$_POST['mobile'];
$email=$_POST['email'];
<body>
<a href="index.php">Home</a>
<br/><br/>
<?php
// include database connection file
include_once("config.php");