You are on page 1of 4

Koneksi.

php

<?php
$koneksi=new mysqli("localhost","root","","uts");
?>

View.php
<?php
session_start();
include 'koneksi.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>data mahasiswa</title>
</head>
<body>
<h2>Data Mahasiswa</h2>
<table class="table" width = 500 border =1>
<thead>
<tr>
<th>no</th>
<th>nama</th>
<th>npm</th>
<th>kelas</th>
<th>aksi</th>
<th>aksi</th>
</tr>
</thead>
<?php $nomor=1; ?>
<?php $ambil=$koneksi->query("SELECT * FROM kelas"); ?>
<?php while($data=$ambil->fetch_assoc()) { ?>
<tbody>
<tr>
<td><?php echo $nomor; ?></td>
<td><?php echo $data['nama']; ?></td>
<td><?php echo $data['kelas']; ?></td>
<td><?php echo $data['npm'];; ?></td>
<td><a href="edit.php?id=<?php echo $data['no']; ?>">edit</a></td>
<td><a href="delete.php?id=<?php echo $data['no']; ?>">delete</a></td>

</tr>
</tbody>
<?php $nomor++; ?>
<?php } ?>
</table>
<br>
<button type="submit"><a href="tambah.php">tambah data</a></button>
</body>
</html>
Edit.php

<?php
session_start();
include 'koneksi.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>edit data mahasiswa</title>
</head>
<body>
<h2>edit data</h2>
<?php $ambil=$koneksi->query("SELECT * FROM kelas"); ?>
<?php $data=$ambil->fetch_assoc(); ?>
<form method="post">
<table class="table" width="500" >
<tr>
<th>Nama : </th>
<td ><input type="text" name="nama" value="<?php echo $data['nama']; ?>"></td>
</tr>
<tr>
<th>kelas : </th>
<td><input type="text" name="kelas" value="<?php echo $data['kelas']; ?>"></td>
</tr>
<tr>
<th>npm :</th>
<td><input type="number" name="npm" value="<?php echo $data['npm']; ?>"></td>
</tr>

</table>
<button type="submit" name="edit">edit</button>
</form>
<?php if (isset($_POST["edit"]))
{
$koneksi->query("UPDATE kelas SET nama='$_POST[nama]',kelas='$_POST[kelas]',
npm='$_POST[npm]' WHERE no='$_GET[id]'");

echo"<script>location='view.php';</script>";
}

?>
</body>
</html>
Delete.php

<?php
session_start();
include 'koneksi.php';
$koneksi->query("DELETE FROM kelas WHERE
no='$_GET[id]'");
echo "<script>location='view.php';</script>";
?>

Tambah.php
<?php
session_start();
include 'koneksi.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>input data</title>
</head>
<body>
<h2>input data</h2>
<form method="post">
<table width="300">
<tr>
<th>nama</th>
<td><input type="text" name="nama"></td>
</tr>
<tr>
<th>kelas</th>
<td><input type="text" name="kelas"></td>
</tr>
<tr>
<th>npm</th>
<td><input type="number" name="npm"></td>
</tr>
</table><br>
<button name="tambah" type="submit">simpan</button>
</form>
<?php if (isset($_POST['tambah']))
{
$koneksi->query("INSERT INTO kelas (nama,kelas,npm) VALUES
('$_POST[nama]','$_POST[kelas]','$_POST[npm]')");
echo "<meta http-equiv='refresh' content='1;url=view.php'>";
}
?>
</body>
</html>
Output

You might also like