Sei sulla pagina 1di 9

Delete

<?php

include "koneksi.php";

$id=$_GET['id'];

$query = mysqli_query($host, "DELETE FROM mahasiswa WHERE id = '$id'");

if($query)

echo "<script type='text/javascript'>

alert('Deleted');

window.location.href='view.php';

</script>

";

?>

EDIT
<!DOCTYPE html>

<html>

<head>

<h1 align="center"> ACTIVITY MINGGU 3 </h1>

</head>

<body>

<div align="center">

<?php
include "koneksi.php";

?>

<form name="form_edit" action="update.php" method="post">

<?php

$id = $_POST['id'];

$query = mysqli_query($host, "SELECT * FROM mahasiswa WHERE id = $id");

while ($data = mysqli_fetch_array($query, MYSQLI_BOTH))

?>

<input type="hidden" name="id" value="<?php echo $data['id']; ?>" />

Masukkan Nama : <input type="text" name="nama" value="<?php echo $data['nama']; ?>"


/>

Masukkan Umur : <input type="text" name="umur" value="<?php echo $data['umur']; ?>" />

<?php } ?>

<input type="submit" name="submit" value="edit" />

</form>

</div>

</body>

</html>

Index
<!DOCTYPE html>

<html>
<head>

<style>

input[type=text], select

width: 100%;

padding: 12px 20px;

margin: 8px 0;

display: inline-block;

border: 1px solid #ccc;

border-radius: 4px;

box-sizing: border-box;

input[type=submit]

width: 100%;

background-color: #4CAF50;

color: white;

padding: 14px 20px;

margin: 8px 0;

border: none;

border-radius: 4px;

cursor: pointer;

}
input[type=submit]:hover

background-color: #45a049;

div

border-radius: 5px;

background-color: #f2f2f2;

padding: 20px;

</style>

<h1 align="center"> ACTIVITY MINGGU 3 </h1>

<body>

<div align="center">

<form name="form_input" action="insert.php" method="post">

Masukkan Nama : <input type="text" name="nama"/>

Masukkan Umur : <input type="text" name="umur"/>

<input type="submit" name="submit" value="insert"/>

</form>

<a href="view.php"> Lihat Data </a>

</div>

</body>

</head>

</html>
Insert
<?php

include "koneksi.php";

$nama = $_POST['nama'];

$umur = $_POST['umur'];

mysqli_query($host, "INSERT INTO mahasiswa VALUES ('', '$nama', '$umur')");

?>

KONEKSI
<?php

$host = mysqli_connect("localhost", "root", "3ia01");

if($host)

echo "Host connection success <br/>";

else

echo "Host connection failed <br/>";

$db = mysqli_select_db($host, "activity_m3");

if($db)
{

echo "Database connection success <br/>";

else

echo "Database connection failed <br/>";

?>

UPDATE
<?php

include "koneksi.php";

$id = $_POST['id'];

$nama = $_POST['nama'];

$umur = $_POST['umur'];

$query = mysqli_query($host, "UPDATE mahasiswa SET nama='$nama', umur='$umur' WHERE id =


'$id'");

if ($query)

echo "<script type='text/javascript'>

alert('Updated');

window.location.href='view.php';

</script>

";

}
?>

VIEW
<!DOCTYPE html>

<html>

<head>

<style>

table

border-collapse: collapse;

width: 100%;

th, td

text-align: left;

padding: 8px;

tr:nth-child(even){background-color: #f2f2f2}

th

background-color: #4CAF50;

color: white;
}

</style>

<h1 align="center"> ACTIVITY MINGGU 3</h1>

<body>

<div align="center">

<?php

include "koneksi.php";

?>

<a href="index.php"> Tambah Data </a>

<table cellspacing="5">

<th> id </th>

<th> Nama </th>

<th> Umur </th>

<th colspan="2"> Proses </th>

<th> </th>

<?php

$query = mysqli_query($host, "SELECT * FROM mahasiswa");

while ($data = mysqli_fetch_array($query, MYSQLI_BOTH))

?>

<tr>

<td> <?php echo $data['id']; ?> </td>

<td> <?php echo $data['nama']; ?> </td>

<td> <?php echo $data['umur']; ?> </td>

<td><a href="edit.php?id=<?php echo $data['id']; ?>">edit</a></td>


<td><a href="delete.php?id=<?php echo $data['id']; ?>">delete</a>QA\A</td>

</tr>

<?php } ?>

</table>

</div>

</body>

</head>

</html>

Potrebbero piacerti anche