Daftar dan Belajar Sekarang!

Cara membuat script edit dan delete

foto fifi14
2 Kontribusi 1 Coto
2 bulan yang lalu
Permisi gan gw mau tanya nih, gimana sih ini cara supaya icon edit sama delete bisa berfungsi? Codingnya apaan ya gan? Tolong dibantu dong, please >.< <?php include "conn.php"; if(isset($_POST['submit'])){ $nama_kelas=strtoupper(htmlentities($_POST['nama_kelas'])); $query=mysql_query("insert into setup_kelas values('','$nama_kelas')"); if($query){ ?><script language="javascript">document.location.href="?page=setup_kelas&status=1";</script><?php }else{ ?><script language="javascript">document.location.href="?page=setup_kelas&status=2";</script><?php } }else{ unset($_POST['submit']); } ?> <!-- start page-heading --> <div id="page-heading"> <h1>Setup Kelas</h1> </div> <!-- end page-heading --> <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table"> <tr> <th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th> <th class="topleft"></th> <td id="tbl-border-top">&nbsp;</td> <th class="topright"></th> <th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th> </tr> <tr> <td id="tbl-border-left"></td> <td> <div id="content-table-inner"> <?php if($_GET['status']=='1'){ ?> <div id="message-green"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td class="green-left">Alhamdulilah sesuatu banget, Data berhasil disimpan :)</td> <td class="green-right"><a class="close-green"><img src="images/table/icon_close_green.gif" alt="" /></a></td> </tr> </table> </div> <?php } if($_GET['status']=='0'){ ?> <div id="message-red"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr> <td class="red-left">Yach data gagal di simpan, cape dech!</td> <td class="red-right"><a class="close-red"><img src="images/table/icon_close_red.gif" alt="" /></a></td> </tr> </table> </div> <?php } ?> <form action="?page=setup_kelas" method="post"> <table border="0" width="100%" cellpadding="0" cellspacing="0"> <tr valign="top"> <td><!-- start step-holder --> <!-- end step-holder --> <!-- start id-form --> <table border="0" cellpadding="0" cellspacing="0" id="id-form"> <tr> <th valign="top">Nama Kelas </th> <td><input type="text" class="inp-form" name="nama_kelas"/></td> <td></td> </tr> <tr> <th>&nbsp;</th> <td valign="top"><input type="submit" name="submit" value="" class="form-submit" /> <input type="reset" value="" class="form-reset" /> </td> <td></td> </tr> </table> </td> <td> </td> </tr> <tr> <td><img src="images/shared/blank.gif" width="695" height="1" alt="blank" /></td> <td></td> </tr> </table> </form> <form id="mainform" action=""> <table border="0" width="61%" cellpadding="0" cellspacing="0" id="product-table"> <tr> <th width="16%" class="table-header-repeat line-left minwidth-1"><a href="">Nomor</a> </th> <th width="68%" class="table-header-repeat line-left minwidth-1"><a href="">Nama Mata Pelajaran</a></th> <th width="16%" class="table-header-options line-left"><a href="">Aksi</a></th> </tr> <?php $view=mysql_query("select * from setup_kelas order by nama_kelas asc"); $no=0; while($row=mysql_fetch_array($view)){ ?> <tr> <td><?php echo $no=$no+1;?></td> <td><?php echo $row['nama_kelas'];?></td> <td class="options-width"> <a href="" title="Delete" class="icon-2 info-tooltip"></a> <a href="" title="Edit" class="icon-5 info-tooltip"></a> </td> </tr> <?php } ?> </table> </form>
  • tolong kodenya masukkan ke tag [code] isi kode ... [/code] biar rapi - dianarifr

Jawaban
foto ilmanhuda
3 Kontribusi 0 Coto
2 bulan yang lalu
href="delete.php?id=<?php echo $d['id']; ?>" href="edit.php?id=<?php echo $d['id']; ?>" silahkan di tambah kan href seperti ini , tinggal di sesuaikan nama file dan primary key nya.
  • Udah kak. Udah aku buat begitu. Trus scriptnya yang di dalam delete.php sama edit.php apa yaa? tolong dibantu dong kak? aku udah coba buat tapi kok nggak bisa dipake buat edit atau delete yah? pleaseeee bantuin :( - fifi14

foto arifhd22
4 Kontribusi 1 Coto
1 bulan yang lalu
<?php //koneksi database include "../../inc/inc.koneksi.php"; $ID = $_POST['id']; $queryD = "DELETE FROM setup_kelas WHERE id=$ID"; mysql_query($queryD); ?>

foto ZedA
3 Kontribusi 1 Coto
1 bulan yang lalu
Untuk edit hampir mirip dengan insert, bedanya tampilkan dahulu data yang ingin diedit, pada sql tambahkan where id=$_POST['id'], terus di <input type="text"...> tambahkan value="<?php $row['nama_kelas'];?>", lalu $query=mysql_query("update setup_kelas set nama_kelas='$nama_kelas' where id=$_POST['id']");

foto Rilham
159 Kontribusi 52 Coto
1 bulan yang lalu
Untuk update dan delete data kurang lebih kodingnya seperti ini
<?php  
// edit / update data

//asumsi koneksinya disimpan dengan nama $koneksi
if(isset($_POST['submit'])){
	$id = $_POST['id'];
	$field1 = $_POST['field1'];
	$field2 = $_POST['field2'];

	$sql = "UPDATE table SET field1 = '$field1', field2 = '$field2' WHERE id = $id";
	$query = mysqli_query($koneksi, $sql);
}


//nama table dan field bisa disesuaikan sendiri
?>
<?php
$id = $_GET['id'];
$sql = "DELETE FROM table WHERE id = $id";
$query = mysqli_query($koneksi, $sql);

?>


Login untuk diksusi di forum sekolah koding

Seikhlas Info

Fitur baru: "Komentar"! baca ini ya
Bikin forum yang nyaman, santai dan sopan