Postingan lainnya
Ngga bisa Update database
Permisi, mau bertanya.. ini ada crud dalam 1 halaman, saya bingung tinggal bagian post update ko dia malah kaya hanya refresh saja ya.. makasih yang sudah mau membantu,,
<?php
// --- koneksi ke database
$koneksi = mysqli_connect ('localhost', 'root', '', 'skp') or die(mysqli_error());
function ubah($koneksi){
// ubah data
if(isset($_POST['btn_ubah'])){
$id = $_POST['id'];
$penilai = $_POST['penilai'];
$dinilai = $_POST['dinilai'];
$kegiatan = $_POST['kegiatan'];
$tkredit = $_POST['tkredit'];
$t_ak = $_POST['t_ak'];
$t_out = $_POST['t_out'];
$t_satuan = $_POST['t_satuan'];
$t_kual = $_POST['t_kual'];
$t_waktu = $_POST['t_waktu'];
$t_satwaktu = $_POST['t_satwaktu'];
$t_biaya = $_POST['t_biaya'];
$tahun = $_POST['tahun'];
if(!empty($tahun) && !empty($kegiatan)){
$perubahan = "penilai='".$penilai."',dinilai=".$dinilai.",kegiatan=".$kegiatan.",tkredit='".$tkredit.",t_ak='".$t_ak.",t_out='".$t_out.",t_satuan='".$t_satuan.",t_biaya='".$t_biaya.",tahun='".$tahun."'";
$sql_update = "UPDATE penilaian SET ".$perubahan." WHERE id=$id";
$update = mysqli_query($koneksi, $sql_update);
if($update && isset($_GET['aksi'])){
if($_GET['aksi'] == 'update'){
header('location: coba.php');
}
}
} else {
$pesan = "Data tidak lengkap!";
}
}
// tampilkan form ubah
if(isset($_GET['id'])){
?>
<a href="coba.php"> « Home</a> |
<a href="coba.php?aksi=create"> (+) Tambah Data</a>
<hr>
<table border=1>
<fieldset>
<legend><h2>Ubah data</h2></legend>
<form action="" method="POST">
<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>"/>
<tr>
<td>Tahun</td>
<td>
<select name="tahun"><option value="<?php echo $_GET['tahun']; ?>">=== Pilih Tahun ===</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
</select>
</td>
<tr>
<td>Pegawai Penilai</td><td><input type="text" name="penilai" value="<?php echo $_GET['penilai']; ?>"></td>
</tr>
<tr>
<td>Pegawai yang dinilai</td><td><input type="text" name="dinilai" value="<?php echo $_GET['dinilai']; ?>"></td>
</tr>
<tr>
<td>Kegiatan</td><td><textarea cols=13 rows=6 name="kegiatan" alue="<?php echo $_GET['t_out']; ?>"/></textarea></td>
</tr>
<tr>
<td>Kredit</td><td><input type="text" class="kredit" name="tkredit" style="width:55px;" value="<?php echo $_GET['tkredit']; ?>"/></td>
</tr>
<tr>
<td>Angka Kredit</td><td><input class="ak_1" type=text name="t_ak" value="<?php echo $_GET['t_ak']; ?>"/></td>
</tr>
<tr>
<td>Kuant/Out</td><td><input type=text style="width:55px;" name="t_out" value="<?php echo $_GET['t_out']; ?>"/><input type="text" name="t_satuan" value="<?php echo $_GET['t_satuan']; ?>"></td>
</tr>
<tr>
<td>Kual/Mutu</td><td><input type=text placeholder="Kual/Mutu" style="width:55px;" name="t_kual" value="<?php echo $_GET['t_kual']; ?>"/></td>
</tr>
<tr>
<td>Waktu</td><td><input type=text style="width:50px;" name="t_waktu" value="<?php echo $_GET['t_waktu']; ?>"/>
<input type=text id="waktu1" style="width:60px;" name="t_satwaktu" value="<?php echo $_GET['t_satwaktu']; ?>"/></td>
<tr>
<td>Biaya</td><td><input type=text style="width:50px;" name="t_biaya" value="<?php echo $_GET['t_biaya']; ?>"/></td>
</tr>
<tr>
<td colspan="2"><label><input type="submit" name="btn_ubah" value="Simpan Perubahan"/> atau <a href="coba.php?aksi=delete&id=<?php echo $_GET['id'] ?>"> (x) Hapus data ini</a>!
</label></td>
</tr>
<p><?php echo isset($pesan) ? $pesan : "" ?></p>
</fieldset>
</form>
</table>
<?php
}
}
if (isset($_GET['aksi'])){
switch($_GET['aksi']){
case "create":
echo '<a href="coba.php"> « Home</a>';
tambah($koneksi);
break;
case "read":
tampil_data($koneksi);
break;
case "update":
ubah($koneksi);
break;
default:
echo "<h3>Aksi <i>".$_GET['aksi']."</i> tidaka ada!</h3>";
tambah($koneksi);
tampil_data($koneksi);
}
} else {
tambah($koneksi);
tampil_data($koneksi);
}
?>
10 Jawaban:
<form action=""
actionnya kosong, jadi cuma ngerefresh page gak memproses apa2
iya saya kosongin gan karna crudnya itu satu halaman ga dipisah2.. itu saya hanya mencopy codingan yg bagian update saja..
meskipun satu halaman tetep harus diisi( dengan nama file itu sendiri, karena prosesnya difile tersebut), kalo kosong tidak akan melakukan apa2 dengan data yang ada dalam form.
sudah diisi halaman itu sendiri, tp ga bisa juga.. padahal kalau input bisa padahal actionnya kosong.. apa ada salah di query updatenya gan?
itu ada pemanggilan fungsi tambah($koneksi) dan tampil data tapi fungsinya kok tidak ada disitu?
nih gan sebelumnya saya ambil dari codingan berikut, dan berhasil semua CRUDnya :
<html>
<head>
<title>CRUD Petani Kode</title>
<link rel="icon" href="http://www.petanikode.com/favicon.ico" />
</head>
<body>
<?php
// --- koneksi ke database
$koneksi = mysqli_connect("localhost","root","","pertanian") or die(mysqli_error());
// --- Fngsi tambah data (Create)
function tambah($koneksi){
if (isset($_POST['btn_simpan'])){
$id = time();
$nm_tanaman = $_POST['nm_tanaman'];
$hasil = $_POST['hasil'];
$lama = $_POST['lama'];
$tgl_panen = $_POST['tgl_panen'];
if(!empty($nm_tanaman) && !empty($hasil) && !empty($lama) && !empty($tgl_panen)){
$sql = "INSERT INTO tabel_panen (id,nama_tanaman, hasil_panen, lama_tanam, tanggal_panen) VALUES(".$id.",'".$nm_tanaman."','".$hasil."','".$lama."','".$tgl_panen."')";
$simpan = mysqli_query($koneksi, $sql);
if($simpan && isset($_GET['aksi'])){
if($_GET['aksi'] == 'create'){
header('location: coba.php');
}
}
} else {
$pesan = "Tidak dapat menyimpan, data belum lengkap!";
}
}
?>
<form action="" method="POST">
<fieldset>
<legend><h2>Tambah data</h2></legend>
<label>Nama tanaman <input type="text" name="nm_tanaman" /></label> <br>
<label>Hasil panen <input type="number" name="hasil" /> kg</label><br>
<label>Lama tanam <input type="number" name="lama" /> bulan</label> <br>
<label>Tanggal panen <input type="date" name="tgl_panen" /></label> <br>
<br>
<label>
<input type="submit" name="btn_simpan" value="Simpan"/>
<input type="reset" name="reset" value="Besihkan"/>
</label>
<br>
<p><?php echo isset($pesan) ? $pesan : "" ?></p>
</fieldset>
</form>
<?php
}
// --- Tutup Fngsi tambah data
// --- Fungsi Baca Data (Read)
function tampil_data($koneksi){
$sql = "SELECT * FROM tabel_panen";
$query = mysqli_query($koneksi, $sql);
echo "<fieldset>";
echo "<legend><h2>Data Panen</h2></legend>";
echo "<table border='1' cellpadding='10'>";
echo "<tr>
<th>ID</th>
<th>Nama Tanaman</th>
<th>Hasil Panen</th>
<th>Lama Tanam</th>
<th>Tanggal Panen</th>
<th>Tindakan</th>
</tr>";
while($data = mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $data['id']; ?></td>
<td><?php echo $data['nama_tanaman']; ?></td>
<td><?php echo $data['hasil_panen']; ?> Kg</td>
<td><?php echo $data['lama_tanam']; ?> bulan</td>
<td><?php echo $data['tanggal_panen']; ?></td>
<td>
<a href="coba.php?aksi=update&id=<?php echo $data['id']; ?>&nama=<?php echo $data['nama_tanaman']; ?>&hasil=<?php echo $data['hasil_panen']; ?>&lama=<?php echo $data['lama_tanam']; ?>&tanggal=<?php echo $data['tanggal_panen']; ?>">Ubah</a> |
<a href="coba.php?aksi=delete&id=<?php echo $data['id']; ?>">Hapus</a>
</td>
</tr>
<?php
}
echo "</table>";
echo "</fieldset>";
}
// --- Tutup Fungsi Baca Data (Read)
// --- Fungsi Ubah Data (Update)
function ubah($koneksi){
// ubah data
if(isset($_POST['btn_ubah'])){
$id = $_POST['id'];
$nm_tanaman = $_POST['nm_tanaman'];
$hasil = $_POST['hasil'];
$lama = $_POST['lama'];
$tgl_panen = $_POST['tgl_panen'];
if(!empty($nm_tanaman) && !empty($hasil) && !empty($lama) && !empty($tgl_panen)){
$perubahan = "nama_tanaman='".$nm_tanaman."',hasil_panen=".$hasil.",lama_tanam=".$lama.",tanggal_panen='".$tgl_panen."'";
$sql_update = "UPDATE tabel_panen SET ".$perubahan." WHERE id=$id";
$update = mysqli_query($koneksi, $sql_update);
if($update && isset($_GET['aksi'])){
if($_GET['aksi'] == 'update'){
header('location: coba.php');
}
}
} else {
$pesan = "Data tidak lengkap!";
}
}
// tampilkan form ubah
if(isset($_GET['id'])){
?>
<a href="coba.php"> « Home</a> |
<a href="coba.php?aksi=create"> (+) Tambah Data</a>
<hr>
<form action="" method="POST">
<fieldset>
<legend><h2>Ubah data</h2></legend>
<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>"/>
<label>Nama tanaman <input type="text" name="nm_tanaman" value="<?php echo $_GET['nama'] ?>"/></label> <br>
<label>Hasil panen <input type="number" name="hasil" value="<?php echo $_GET['hasil'] ?>"/> kg</label><br>
<label>Lama tanam <input type="number" name="lama" value="<?php echo $_GET['lama'] ?>"/> bulan</label> <br>
<label>Tanggal panen <input type="date" name="tgl_panen" value="<?php echo $_GET['tanggal'] ?>"/></label> <br>
<br>
<label>
<input type="submit" name="btn_ubah" value="Simpan Perubahan"/> atau <a href="coba.php?aksi=delete&id=<?php echo $_GET['id'] ?>"> (x) Hapus data ini</a>!
</label>
<br>
<p><?php echo isset($pesan) ? $pesan : "" ?></p>
</fieldset>
</form>
<?php
}
}
// --- Tutup Fungsi Update
// --- Fungsi Delete
function hapus($koneksi){
if(isset($_GET['id']) && isset($_GET['aksi'])){
$id = $_GET['id'];
$sql_hapus = "DELETE FROM tabel_panen WHERE id=" . $id;
$hapus = mysqli_query($koneksi, $sql_hapus);
if($hapus){
if($_GET['aksi'] == 'delete'){
header('location: coba.php');
}
}
}
}
// --- Tutup Fungsi Hapus
// ===================================================================
// --- Program Utama
if (isset($_GET['aksi'])){
switch($_GET['aksi']){
case "create":
echo '<a href="coba.php"> « Home</a>';
tambah($koneksi);
break;
case "read":
tampil_data($koneksi);
break;
case "update":
ubah($koneksi);
tampil_data($koneksi);
break;
case "delete":
hapus($koneksi);
break;
default:
echo "<h3>Aksi <i>".$_GET['aksi']."</i> tidaka ada!</h3>";
tambah($koneksi);
tampil_data($koneksi);
}
} else {
tambah($koneksi);
tampil_data($koneksi);
}
?>
</body>
</html>
ini setelah saya edit, hanya bagian updatnya saja yg ngga bisa..
<html>
<head>
<title>Penilaian Kinerja Pegawai</title>
</head>
<body>
<?php
// --- koneksi ke database
$koneksi = mysqli_connect ('localhost', 'root', '', 'skp') or die(mysqli_error());
// --- Fngsi tambah data (Create)
function tambah($koneksi){
if (isset($_POST['btn_simpan'])){
$id = time();
$penilai = $_POST['penilai'];
$dinilai = $_POST['dinilai'];
$kegiatan = $_POST['kegiatan'];
$tkredit = $_POST['tkredit'];
$t_ak = $_POST['t_ak'];
$t_out = $_POST['t_out'];
$t_satuan = $_POST['t_satuan'];
$t_kual = $_POST['t_kual'];
$t_waktu = $_POST['t_waktu'];
$t_satwaktu = $_POST['t_satwaktu'];
$t_biaya = $_POST['t_biaya'];
$tahun = $_POST['tahun'];
if(!empty($tahun) && !empty($kegiatan)){
$sql = "insert into penilaian (id,penilai, dinilai, kegiatan, tkredit, t_ak, t_out, t_satuan, t_kual, t_waktu, t_satwaktu, t_biaya, tahun)
values
('$id','$penilai','$dinilai','$kegiatan','$tkredit','$t_ak','$t_out','$t_satuan','$t_kual','$t_waktu','$t_satwaktu','$t_biaya','$tahun')";
$simpan = mysqli_query($koneksi, $sql);
if($simpan && isset($_GET['aksi'])){
if($_GET['aksi'] == 'create'){
header('location: coba.php');
}
}
} else {
$pesan = "Tidak dapat menyimpan, data belum lengkap!";
}
}
?>
<fieldset>
<table>
<form action="" method="POST">
<legend><h2>Tambah data</h2></legend>
<tr>
<td><label>Tahun</label></td>
<td><select name="tahun"><option value="#">=== Pilih Tahun ===</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
</select></label>
</td>
<tr>
<td><label>Pegawai Penilai</td><td><input type="text" name="penilai" value="<?php echo $penilai = $_GET['penilai']; ?>"/></label></td>
</tr>
<tr>
<td><label>Pegawai yang Dinilai</td><td><input type="text" name="dinilai" value="<?php echo $penilai = $_GET['dinilai']; ?>"/></label></td>
</tr>
<tr>
<td><label>Kegiatan</td><td><textarea name="kegiatan"></textarea></label></td>
</tr>
<tr>
<td><label>Kredit</td><td><input type="text" name="tkredit" /></label></td>
</tr>
<tr>
<td><label>Angka Kredit</td><td><input type="text" name="t_ak" /></label></td>
</tr>
<tr>
<td><label>Kuant / Out</td><td><input type="text" name="t_out" /><input type="text" name="t_satuan"></label></td>
</tr>
<tr>
<td><label>Kual / Mutu</td><td><input type="text" name="t_kual" /></label> <br></td>
</tr>
<tr>
<td><label>Waktu</td><td><input type="text" name="t_waktu" /><input type="text" name="t_satwaktu"></label></td>
<tr>
<td><label>Biaya</td><td><input type="text" name="t_biaya" /></label></td>
</tr>
<tr><td>
<label><input type="submit" name="btn_simpan" value="Simpan"/>
<input type="reset" name="reset" value="Besihkan"/></label></td>
</tr>
<p><?php echo isset($pesan) ? $pesan : "" ?></p>
</fieldset>
</form>
</table>
<?php
}
// --- Tutup Fngsi tambah data
// --- Fungsi Baca Data (Read)
function tampil_data($koneksi){
$sql = "SELECT * FROM penilaian";
$query = mysqli_query($koneksi, $sql);
echo "<fieldset>";
echo "<legend><h2>Data SKP</h2></legend>";
echo "<table border='1' cellpadding='10'>";
echo "<th>No</th>
<th style=width:400px;>Kegiatan</th>
<th> Kredit</th>
<th> AK</th>
<th colspan=2>kuant/Out</th>
<th> Kual/Mutu</th>
<th colspan=2>Waktu</th><th>Biaya</th>
<th> AK</th>
<th colspan=2>kuant/output</th>
<th colspan2>kual/mutu</th>
<th colspan=2>waktu</th>
<th>Biaya</th>
</tr>";
while($data = mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $data['id']; ?></td>
<td style="width:55px;"><?php echo $data['kegiatan']; ?></td>
<td><?php echo $data['tkredit'];?></td>
<td><?php echo $data['t_ak']; ?></td>
<td><?php echo $data['t_out']; ?></td>
<td><?php echo $data['t_satuan']; ?></td>
<td><?php echo $data['t_kual']; ?></td>
<td><?php echo $data['t_waktu']; ?></td>
<td><?php echo $data['t_satwaktu']; ?></td>
<td><?php echo $data['t_biaya']; ?></td>
<td><?php echo $data['r_ak']; ?></td>
<td><?php echo $data['r_out']; ?></td>
<td><?php echo $data['r_satuan']; ?></td>
<td><?php echo $data['r_kual']; ?></td>
<td><?php echo $data['r_waktu']; ?></td>
<td><?php echo $data['r_satwaktu']; ?></td>
<td><?php echo $data['r_biaya']; ?></td>
<td>
<a href="coba.php?aksi=update&id=<?php echo $data['id']; ?>&tahun=<?php echo $data['tahun']; ?>&penilai=<?php echo $data['penilai']; ?>&dinilai=<?php echo $data['dinilai']; ?>&kegiatan=<?php echo $data['kegiatan']; ?>&tkredit=<?php echo $data['tkredit']; ?>&t_ak=<?php echo $data['t_ak']; ?>&t_out=<?php echo $data['t_out']; ?>&t_satuan=<?php echo $data['t_satuan']; ?>&t_kual=<?php echo $data['t_kual']; ?>&t_waktu=<?php echo $data['t_waktu']; ?>&t_satwaktu=<?php echo $data['t_satwaktu']; ?>&t_biaya=<?php echo $data['t_biaya']; ?>">Target</a> |
<a href="real.php?aksi=update&id=<?php echo $data['id']; ?>&tahun=<?php echo $data['tahun']; ?>&penilai=<?php echo $data['penilai']; ?>&dinilai=<?php echo $data['dinilai']; ?>&kegiatan=<?php echo $data['kegiatan']; ?>&tkredit=<?php echo $data['tkredit']; ?>&t_ak=<?php echo $data['t_ak']; ?>&t_out=<?php echo $data['t_out']; ?>&t_satuan=<?php echo $data['t_satuan']; ?>&t_kual=<?php echo $data['t_kual']; ?>&t_waktu=<?php echo $data['t_waktu']; ?>&t_satwaktu=<?php echo $data['t_satwaktu']; ?>&t_biaya=<?php echo $data['t_biaya']; ?>">Realisasi</a>|
<a href="coba.php?aksi=delete&id=<?php echo $data['id']; ?>">Hapus</a>
</td>
</tr>
<?php
}
echo "</table>";
echo "</fieldset>";
}
// --- Tutup Fungsi Baca Data (Read)
// --- Fungsi Ubah Data (Update)
function ubah($koneksi){
// ubah data
if(isset($_POST['btn_ubah'])){
$id = $_POST['id'];
$penilai = $_POST['penilai'];
$dinilai = $_POST['dinilai'];
$kegiatan = $_POST['kegiatan'];
$tkredit = $_POST['tkredit'];
$t_ak = $_POST['t_ak'];
$t_out = $_POST['t_out'];
$t_satuan = $_POST['t_satuan'];
$t_kual = $_POST['t_kual'];
$t_waktu = $_POST['t_waktu'];
$t_satwaktu = $_POST['t_satwaktu'];
$t_biaya = $_POST['t_biaya'];
$tahun = $_POST['tahun'];
if(!empty($tahun) && !empty($kegiatan)){
$perubahan = "penilai='".$penilai."',dinilai=".$dinilai.",kegiatan=".$kegiatan.",tkredit='".$tkredit.",t_ak='".$t_ak.",t_out='".$t_out.",t_satuan='".$t_satuan.",t_biaya='".$t_biaya.",tahun='".$tahun."'";
$sql_update = "UPDATE penilaian SET ".$perubahan." WHERE id=$id";
$update = mysqli_query($koneksi, $sql_update);
if($update && isset($_GET['aksi'])){
if($_GET['aksi'] == 'update'){
header('location: coba.php');
}
}
} else {
$pesan = "Data tidak lengkap!";
}
}
// tampilkan form ubah
if(isset($_GET['id'])){
?>
<a href="coba.php"> « Home</a> |
<a href="coba.php?aksi=create"> (+) Tambah Data</a>
<hr>
<table border=1>
<fieldset>
<legend><h2>Ubah data</h2></legend>
<form action="" method="POST">
<input type="hidden" name="id" value="<?php echo $_GET['id'] ?>"/>
<tr>
<td>Tahun</td>
<td>
<select name="tahun"><option value="<?php echo $_GET['tahun']; ?>">=== Pilih Tahun ===</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
<option value="2022">2022</option>
<option value="2023">2023</option>
<option value="2024">2024</option>
<option value="2025">2025</option>
<option value="2026">2026</option>
<option value="2027">2027</option>
<option value="2028">2028</option>
</select>
</td>
<tr>
<td>Pegawai Penilai</td><td><input type="text" name="penilai" value="<?php echo $_GET['penilai']; ?>"></td>
</tr>
<tr>
<td>Pegawai yang dinilai</td><td><input type="text" name="dinilai" value="<?php echo $_GET['dinilai']; ?>"></td>
</tr>
<tr>
<td>Kegiatan</td><td><textarea cols=13 rows=6 name="kegiatan"><?php echo $_GET['t_out']; ?></textarea></td>
</tr>
<tr>
<td>Kredit</td><td><input type="text" class="kredit" name="tkredit" style="width:55px;" value="<?php echo $_GET['tkredit']; ?>"/></td>
</tr>
<tr>
<td>Angka Kredit</td><td><input class="ak_1" type=text name="t_ak" value="<?php echo $_GET['t_ak']; ?>"/></td>
</tr>
<tr>
<td>Kuant/Out</td><td><input type=text style="width:55px;" name="t_out" value="<?php echo $_GET['t_out']; ?>"/><input type="text" name="t_satuan" value="<?php echo $_GET['t_satuan']; ?>"></td>
</tr>
<tr>
<td>Kual/Mutu</td><td><input type=text placeholder="Kual/Mutu" style="width:55px;" name="t_kual" value="<?php echo $_GET['t_kual']; ?>"/></td>
</tr>
<tr>
<td>Waktu</td><td><input type=text style="width:50px;" name="t_waktu" value="<?php echo $_GET['t_waktu']; ?>"/>
<input type=text id="waktu1" style="width:60px;" name="t_satwaktu" value="<?php echo $_GET['t_satwaktu']; ?>"/></td>
<tr>
<td>Biaya</td><td><input type=text style="width:50px;" name="t_biaya" value="<?php echo $_GET['t_biaya']; ?>"/></td>
</tr>
<tr>
<td colspan="2"><label><input type="submit" name="btn_ubah" value="Simpan Perubahan"/> atau <a href="coba.php?aksi=delete&id=<?php echo $_GET['id'] ?>"> (x) Hapus data ini</a>!
</label></td>
</tr>
<p><?php echo isset($pesan) ? $pesan : "" ?></p>
</form>
</table>
</fieldset>
<?php
}
}
// --- Tutup Fungsi Update
// --- Fungsi Delete
function hapus($koneksi){
if(isset($_GET['id']) && isset($_GET['aksi'])){
$id = $_GET['id'];
$sql_hapus = "DELETE FROM penilaian WHERE id=" . $id;
$hapus = mysqli_query($koneksi, $sql_hapus);
if($hapus){
if($_GET['aksi'] == 'delete'){
header('location: coba.php');
}
}
}
}
// --- Tutup Fungsi Hapus
// ===================================================================
// --- Program Utama
if (isset($_GET['aksi'])){
switch($_GET['aksi']){
case "create":
echo '<a href="coba.php"> « Home</a>';
tambah($koneksi);
break;
case "read":
tampil_data($koneksi);
break;
case "update":
ubah($koneksi);
tampil_data($koneksi);
break;
case "delete":
hapus($koneksi);
break;
default:
echo "<h3>Aksi <i>".$_GET['aksi']."</i> tidaka ada!</h3>";
tambah($koneksi);
tampil_data($koneksi);
}
} else {
tambah($koneksi);
tampil_data($koneksi);
}
?>
</body>
</html>
ini yang codingan atas [link]https://www.dropbox.com/s/8pa7cevetug4sw0/pertanian.sql?dl=0[/link]
ini untuk codingan yg bawah https://www.dropbox.com/s/2u9t9204j8ms0r9/skp.sql?dl=0
terimakasih banget gan sudah mau membantu..
udah fix gan, cuma kalau update yg kedua kalinya suka jd ngga kebaca di textboxnya..