Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Edit tapi Data Ngak Berubah
Suhu Mohon Koreksi data yang Salah ,Soalnya Pas Bagian Edit itu Data Ngak berubah Kenapa ya ?
<!-- Halaman Ubah -->
<div class="panel-body">
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Form Ubah Data</h4>
</div>
<div class="modal-body" id="modal_edit">
<form role="form" method="POST">
<div class="form-group">
<label>Nama Lengkap</label>
<input class="form-control" type="text" name="nama" id="nama" />
</div>
<div class="form-group">
<label>Jenis Kelamin</label>
<select class="form-control" type="text" name="jk" id="jk" >
<option value=" "> </option>
<option value="L">Laki laki</option>
<option value="P ">Perempuan</option></select>
</div>
<div class="form-group">
<label>Tempat Lahir</label>
<input class="form-control" type="text" name="tempat" id="tempat" />
</div>
<div class="form-group">
<label>Tanggal Lahir</label>
<input class="form-control" type="date" name="ttl" id="ttl" />
</div>
<div>
<label>Alamat</label>
<textarea class="form-control" rows="3" name="alamat" id="alamat"></textarea>
</div>
<div class="form-group">
<label>pendidikan terakhir</label>
<input class="form-control" type="text" name="pdk" id="pdk" />
</div>
<div class="form-group">
<label>No Hp / Tlp </label>
<input class="form-control" type="text" name="hp" id="hp" />
</div>
<div class="form-group">
<label>Tujuan</label>
<input class="form-control" type="text" name="tujuan" id="tujuan" />
</div>
<div class="form-group">
<label>Tahun </label>
<input class="form-control" name="th" placeholder="Input Kode" id="th" readonly />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
<button type="submit" name="ubah" class="btn btn-primary">Simpan</button>
</form>
<?php
if(isset($_POST['ubah'])) {
$no = $_POST['no'];
$th = $_POST['th'];
$nama = $_POST['nama'];
$jk = $_POST['jk'];
$tempat = $_POST['tempat'];
$ttl = $_POST['ttl'];
$alamat = $_POST['alamat'];
$pdk = $_POST['pdk'];
$hp = $_POST['hp'];
$tujuan = $_POST['tujuan'];
$no = 0;
$sql = mysqli_query($koneksi, "UPDATE kpn SET th = '$th', nama = '$nama', jk = '$jk', tempat = '$tempat', ttl = '$ttl', pdk = '$pdk', hp = '$hp', tujuan = '$tujuan' WHERE no = '$no' ");
if($sql) {
echo "
<script>
alert('Data Berhasil Diubah');
document.location.href = '';
</script>";
}
}
?>
</div>
</div>
</div>
</div>
</div>
2 Jawaban:
<div>itu variabel $no dipanggil dua kali, yang dibawah di set jadi 0, harusnya dihilangkan.</div>
Tanggapan
udah kak tetap sama hasil nya
<div>Full Source Code <br><br><?php<br>session_start();<br>if(!isset($_SESSION['username'])) {<br> header("Location: login.php");<br> die();<br>}<br>?><br><br> <!DOCTYPE html><br> <html lang="en"><br><br> <head><br> <meta charset="UTF-8"><br> <title></title><br> <link href="assets/css/bootstrap.css" rel="stylesheet" /><br> <!-- FONTAWESOME STYLES--><br> <link href="assets/css/font-awesome.css" rel="stylesheet" /><br> <!-- MORRIS CHART STYLES--><br><br> <!-- CUSTOM STYLES--><br> <link href="assets/css/custom.css" rel="stylesheet" /><br> <!-- GOOGLE FONTS--><br> <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' /><br> <!-- TABLE STYLES--><br> <link href="assets/js/dataTables/dataTables.bootstrap.css" rel="stylesheet" /><br><br> <style><br> span {<br> font-size: 22px;<br> }<br> </style><br> </head><br><br> <body><br> <div class="row"><br> <div class="col-md-12"><br> <!-- Advanced Tables --><br> <div class="panel panel-success"><br> <div class="panel-heading"><br> <span>Database Peserta KPN</span><br> <span title="Tambah Data"><button style="float: right;" class="btn-md btn btn-success"data-toggle="modal" data-target="#myModal"><br> <b>+ Tambah</b><br> </button></span><br> <a class="nav-item nav-link active" href="" style="float: right" class="fas fa-file-alt"><i class="fas fa-user-plus">`</i></a><br> <a class="btn-md btn btn-success" href="kpn-xls.php" style="float: right" class="fas fa-file-alt"><i class="fas fa-user-plus"></i> Export Data</a><br> </div><br> </div><br> <div class="table-responsive"><br> <table class="table table-striped table-bordered table-hover" id="dataTables-example"><br> <thead><br> <tr><br> <th>No.</th><br> <th>Nama Lengkap</th><br> <th>Jenis Kelamin</th><br> <th>Tempat Lahir</th><br> <th>Tanggal Lahir</th><br> <th>Alamat</th><br> <th>Pendidikan Terakhir</th><br> <th>No Hp/Tlp</th><br> <th>Tujuan</th><br> <th>Tahun </th><br> <th>Aksi</th><br> </tr><br> </thead><br> <tbody><br><br> <?php <br> $no = 1;<br> $sql = mysqli_query($koneksi, "SELECT*FROM kpn WHERE no ");<br> while ($data = mysqli_fetch_assoc($sql)) {<br><br> ?><br> <tr class="odd gradeX"><br> <td><br> <?php echo $no++; ?><br> </td><br> <td><br> <?php echo $data['nama']; ?><br> </td><br> <td><br> <?php echo $data['jk']; ?><br> </td><br> <td><br> <?php echo $data['tempat']; ?><br> </td><br> <td><br> <?php echo $data['ttl']; ?><br> </td><br> <td><br> <?php echo $data['alamat']; ?><br> </td><br> <td><br> <?php echo $data['pdk']; ?><br> </td><br> <td><br> <?php echo $data['hp']; ?><br> </td><br> <td> <br> <?php echo $data['tj']; ?><br> </td><br> <td><br> <?php echo $data['th']; ?><br> </td><br> <br> <td><br> <a id="edit_data" data-toggle="modal" data-target="#edit" data-id="<?php echo $data['no']; ?>" data-th="<?php echo $data['th']; ?>" data-nama="<?php echo $data['nama']; ?>" data-jk="<?php echo $data['jk']; ?>" data-tempat="<?php echo $data['tempat']; ?>" data-ttl="<?php echo $data['ttl']; ?>" data-alamat="<?php echo $data['alamat']; ?>" data-pdk="<?php echo $data['pdk']; ?>" data-hp="<?php echo $data['hp']; ?>" data-tj="<?php echo $data['tj']; ?>" class="btn btn-warning btn-md" title="Ubah Data"><i class="fa fa-edit"> </i></a><br> <a onclick="return confirm('Apakah anda yakin ingin menghapus data?')" href="?page=kpn&aksi=hapus&id=<?php echo $data['no'];?>" class="btn btn-danger btn-md" title="Hapus Data"><i class="fa fa-trash"> </i></a><br> </td><br> </tr><br> <?php <br> <br> } <br> ?><br> </tbody><br> </table><br> </div><br><br> <!-- Halaman Tambah--><br> <div class="panel-body"><br> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><br> <div class="modal-dialog"><br> <div class="modal-content"><br> <div class="modal-header"><br> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><br> <h4 class="modal-title" id="myModalLabel">Form Tambah Data</h4><br> </div><br> <div class="modal-body"><br> <form role="form" method="POST"><br> <div class="form-group"><br> <label>Nama Lengkap</label><br> <input class="form-control" type="text" name="nama" /><br> </div><br> <div class="form-group"><br> <label>Jenis Kelamin</label><br> <select class="form-control" type="text" name="jk" ><br> <option value=" "> </option><br> <option value="L">Laki laki</option><br> <option value="P ">Perempuan</option></select><br> </div><br> <div class="form-group"><br> <label>Tempat Lahir</label><br> <input class="form-control" type="text" name="tempat" /><br> </div><br> <div class="form-group"><br> <label>Tanggal Lahir</label><br> <input class="form-control" type="date" name="ttl" /><br> </div><br> <div><br> <label>Alamat</label><br> <textarea class="form-control" rows="3" name="alamat"></textarea><br> </div><br> <div class="form-group"><br> <label>Pendidikan Terakhir</label><br> <input class="form-control" type="text" name="pdk" /><br> </div><br> <div class="form-group"><br> <label>No Hp/Tlpn </label><br> <input class="form-control" type="text" name="hp" /><br> </div><br> <div class="form-group"><br> <label>Tujuan</label><br> <input class="form-control" type="text" name="tj" /><br> </div><br> <div class="form-group"><br> <label>Tahun</label><br> <input class="form-control" name="th" placeholder="Input Kode" /><br> </div><br> </div><br> <div class="modal-footer"><br> <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button><br> <button type="submit" name="simpan" class="btn btn-primary">Simpan</button><br> </form><br> </div><br> </div><br> </div><br> </div><br> </div><br><br> <?php <br> if(isset($_POST['simpan'])) {<br> $no = $_POST['no'];<br> $nama = $_POST['nama'];<br> $jk = $_POST['jk'];<br> $tempat = $_POST['tempat'];<br> $ttl = $_POST['ttl'];<br> $alamat = $_POST['alamat'];<br> $pdk = $_POST['pdk'];<br> $hp = $_POST['hp'];<br> $tj = $_POST['tj'];<br> $th = $_POST['th'];<br><br> $sql = mysqli_query($koneksi, "INSERT INTO kpn (no, th, nama, jk, ttl, tempat, alamat, pdk, hp, tj ) VALUES ('$no', '$th', '$nama', '$jk', '$ttl', '$tempat', '$alamat', '$pdk', '$hp','$tj')");<br><br> if($sql) {<br><br> echo "<br> <script><br> alert('Data Berhasil Ditambahkan');<br> document.location.href = '';<br> </script>"; <br> }<br> }<br> ?><br> <!-- Akhir Halaman Tambah --><br><br> <!-- Halaman Ubah --><br> <div class="panel-body"><br> <div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"><br> <div class="modal-dialog"><br> <div class="modal-content"><br> <div class="modal-header"><br> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><br> <h4 class="modal-title" id="myModalLabel">Form Ubah Data</h4><br> </div><br> <div class="modal-body" id="modal_edit"><br> <form role="form" method="POST"><br> <div class="form-group"><br> <label>Nama Lengkap</label><br> <input class="form-control" type="text" name="nama" id="nama" /><br> </div><br> <div class="form-group"><br> <label>Jenis Kelamin</label><br> <select class="form-control" type="text" name="jk" id="jk" ><br> <option value=" "> </option><br> <option value="L">Laki laki</option><br> <option value="P ">Perempuan</option></select><br> </div><br> <div class="form-group"><br> <label>Tempat Lahir</label><br> <input class="form-control" type="text" name="tempat" id="tempat" /><br> </div><br> <div class="form-group"><br> <label>Tanggal Lahir</label><br> <input class="form-control" type="date" name="ttl" id="ttl" /><br> </div><br> <div><br> <label>Alamat</label><br> <textarea class="form-control" rows="3" name="alamat" id="alamat"></textarea><br> </div><br> <div class="form-group"><br> <label>pendidikan terakhir</label><br> <input class="form-control" type="text" name="pdk" id="pdk" /><br> </div><br> <div class="form-group"><br> <label>No Hp / Tlp </label><br> <input class="form-control" type="text" name="hp" id="hp" /><br> </div><br> <div class="form-group"><br> <label>Tujuan</label><br> <input class="form-control" type="text" name="tujuan" id="tujuan" /><br> </div><br> <div class="form-group"><br> <label>Tahun </label><br> <input class="form-control" name="th" placeholder="Input Kode" id="th" readonly /><br> </div><br> </div><br> <div class="modal-footer"><br> <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button><br> <button type="submit" name="ubah" class="btn btn-primary">Simpan</button><br> </form><br><br> <?php <br> if(isset($_POST['ubah'])) {<br> $no = $_POST['no'];<br> $th = $_POST['th'];<br> $nama = $_POST['nama'];<br> $jk = $_POST['jk'];<br> $tempat = $_POST['tempat'];<br> $ttl = $_POST['ttl'];<br> $alamat = $_POST['alamat'];<br> $pdk = $_POST['pdk'];<br> $hp = $_POST['hp'];<br> $tj = $_POST['tj'];<br><br> <br> $sql = mysqli_query($koneksi, "UPDATE kpn SET th = '$th', nama = '$nama', jk = '$jk', tempat = '$tempat', ttl = '$ttl', pdk = '$pdk', hp = '$hp', tj = '$tj' = 0 WHERE no = '$no' ");<br> if($sql) {<br> echo "<br> <script><br> alert('Data Berhasil Diubah');<br> document.location.href = '';<br> </script>"; <br> }<br> }<br> ?><br><br> </div><br> </div><br> </div><br> </div><br> </div><br> <!-- Akhir Halaman Ubah --><br> </div><br> </div><br> </div><br> </div><br><br> <div class="row"><br> <div class="col-md-12"><br> <br> Developer By <a href="" target="_blank"><b>Will</b></a><br> </div><br> </div><br> </div><br><br> <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script><br><br> <!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME--><br> <!-- JQUERY SCRIPTS --><br> <script src="assets/js/jquery-1.10.2.js"></script><br><br> <script type="text/javascript"><br> $(document).ready(function() {<br> $('#dataTables-example').dataTable();<br> });<br> </script><br><br> <script type="text/javascript"><br> $(document).on("click", "#edit_data", function() {<br> var no = $(this).data('id');<br> var th = $(this).data('th');<br> var nama = $(this).data('nama');<br> var jk = $(this).data('jk');<br> var tempat = $(this).data('tempat');<br> var ttl = $(this).data('ttl');<br> var alamat = $(this).data('alamat');<br> var pdk = $(this).data('pdk');<br> var hp = $(this).data('hp');<br> var tj = $(this).data('tj');<br><br> $("#modal_edit #no").val(no);<br> $("#modal_edit #th").val(th);<br> $("#modal_edit #nama").val(nama);<br> $("#modal_edit #jk").val(jk);<br> $("#modal_edit #tempat").val(tempat);<br> $("#modal_edit #ttl").val(ttl);<br> $("#modal_edit #alamat").val(alamat);<br> $("#modal_edit #pdk").val(pdk);<br> $("#modal_edit #hp").val(hp);<br> $("#modal_edit #tj").val(tj);<br><br> })<br> </script><br><br> </body><br><br> </html></div>