Crud update dan delete gagal

<!-- modal isi tampilan -->
                <tbody>
                  <?php
                  include'../koneksi.php';
                  $no=1;
                  $data = mysqli_query($koneksi,"SELECT * from kas order by kas_id ASC");
                  while($d = mysqli_fetch_array($data)){
                    ?>
                    <tr>
                      <td><?php echo $no++; ?></td>
                      <td class="text-center"><?php echo date('d-m-Y', strtotime($d['kas_tanggal'])); ?></td>
                      <td class="text-center"><?php echo $d['kas_no_akun']; ?></td>
                      <td class="text-center"><?php echo $d['kas_ket']; ?></td>
                      <td class="text-center"><?php echo $d['kas_debet']; ?></td>
                      <td class="text-center"><?php echo $d['kas_kredit']; ?></td>
                      <td class="text-center"><?php echo $d['kas_saldo']; ?></td>
                        <?php
                        if($d['kas_id']){
                          ?>
                          <td>
                          <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#edit_kas_<?php echo $d['kas_id'] ?>">

                            <i class="fa fa-cog"></i>
                          </button>

                          <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#hapus_kas_<?php echo $d['kas_id'] ?>">
                            <i class="fa fa-trash"></i>
                          </button>
                          <?php
                        }
                        ?>
                       <div class="box-body">

                    <!-- modal update-->

                        <form action ="kas_update.php" method="post">
                          <div class="modal fade" id="edit_kas_<?php echo $d['kas_id'] ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                              <div class="modal-content">
                                <div class="modal-header">
                                  <h5 class="modal-title" id="exampleModalLabel">Edit Kas</h5>
                                  <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">×</span>
                                  </button>
                                </div>
                                <div class="modal-body">

                                  <div class="form-group" style="width:100%;">
                                    <label>Tanggal</label>
                                    <input type="hidden" name="id" value="<?php echo $d['kas_id'] ?>">
                                    <input type="text" name="kas_tanggal" required="required" class="form-control datepicker2">
                                  </div>

                                  <div class="form-group" style="width:100%">
                                    <label>No Akun</label>
                                    <input type="hidden" name="id" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_id']; ?>">
                                    <input type="text" name="kas_no_akun" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_no_akun']; ?>" style="width:100%">
                                  </div>

                                   <div class="form-group" style="width:100%">
                                    <label>Keterangan</label>
                                    <input type="hidden" name="id" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_id']; ?>">
                                    <input type="text" name="kas_ket" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_ket']; ?>" style="width:100%">
                                  </div>

                                  <div class="form-group" style="width:100%;margin-bottom:20px">
                                    <label>Jenis</label>
                                    <select name="kas_jenis" style="width:100%" class="form-control" required="required">
                                      <option value="">- Pilih -</option>
                                      <option <?php if($d['kas_jenis'] == "Debet"){echo "selected='selected'";} ?> value="Debet">Debet</option>
                                      <option <?php if($d['kas_jenis'] == "Kredit"){echo "selected='selected'";} ?> value="Kredit">Kredit</option>
                                    </select>
                                  </div>

                                  <div class="form-group" style="width:100%">
                                    <label>Kas Debet</label>
                                    <input type="hidden" name="id" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_id']; ?>">
                                    <input type="text" name="kas_debet" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_debet']; ?>" style="width:100%">
                                  </div>

                                  <div class="form-group" style="width:100%">
                                    <label>Kas Kredit</label>
                                    <input type="hidden" name="id" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_id']; ?>">
                                    <input type="text" name="kas_kredit" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_kredit']; ?>" style="width:100%">
                                  </div>

                                  <div class="form-group" style="width:100%">
                                    <label>Saldo</label>
                                    <input type="hidden" name="id" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_id']; ?>">
                                    <input type="text" name="kas_saldo" required="required" class="form-control" placeholder="Nama Kategori .." value="<?php echo $d['kas_saldo']; ?>" style="width:100%">
                                  </div>

                                </div>
                                <div class="modal-footer">
                                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>
                                  <button type="submit" value="Simpan" class="btn btn-primary">Simpan</button>

                                </div>
                              </div>
                            </div>
                          </div>
                        </form>

<?php
include 'koneksi.php';
// menyimpan data kedalam variabel
$id  = $_POST['kas_id'];
$tanggal  = $_POST['kas_tanggal'];
$no_akun  = $_POST['kas_no_akun'];
$keterangan  = $_POST['kas_ket'];
$jenis  = $_POST['kas_jenis'];
$debet  = $_POST['kas_debet'];
$kredit  = $_POST['kas_kredit'];
$saldo  = $_POST['kas_saldo'];
// query SQL untuk insert data
$sql = "UPDATE kas set kas_tanggal='$tanggal', kas_no_akun='$no_akun', kas_ket='$keterangan', kas_jenis='$jenis', kas_debet='$debet', kas_kredit='$kredit', kas_saldo='$saldo' where kas_id=$id";
mysqli_query($koneksi, $sql);
// mengalihkan ke halaman kas.php
header("location:kas.php");
?>

<?php
include 'koneksi.php';
// menyimpan data id kedalam variabel
$kas   = $_GET['kas_id'];
// query SQL untuk insert data
$query="DELETE from kas where kas_id='$kas'";
mysqli_query($koneksi, $query);
// mengalihkan ke halaman index.php
header("location:kas.php");
?>

avatar ilmirahmadhana
@ilmirahmadhana

4 Kontribusi 0 Poin

Diperbarui 5 tahun yang lalu

3 Jawaban:

ini yang salah dimana ya? update sama delete nya gak bisa ke save di databasenya. padahal untuk insert nya bisa

avatar ilmirahmadhana
@ilmirahmadhana

4 Kontribusi 0 Poin

Dipost 5 tahun yang lalu

nama variablenya salah $query &gt; $sql atau sebaliknya <pre> $sql = "UPDATE kas set kas_tanggal='$tanggal', kas_no_akun='$no_akun', kas_ket='$keterangan', kas_jenis='$jenis', kas_debet='$debet', kas_kredit='$kredit', kas_saldo='$saldo' where kas_id=$id"; mysqli_query($koneksi, $sql); </pre>

avatar dianarifr
@dianarifr

642 Kontribusi 316 Poin

Dipost 5 tahun yang lalu

Tanggapan

sudah diganti tapi tetep gk bisa

yg ga bisa updatenya atau deletenya?

<pre> $sql = "UPDATE kas set kas_tanggal='$tanggal', kas_no_akun='$no_akun', kas_ket='$keterangan', kas_jenis='$jenis', kas_debet='$debet', kas_kredit='$kredit', kas_saldo='$saldo' where kas_id=$id"; mysqli_query($koneksi, $sql); </pre> $query-&gt;$sql

avatar rankoms
@rankoms

89 Kontribusi 12 Poin

Dipost 5 tahun yang lalu

Tanggapan

sudah di ganti tapi tetep gk bisa

Login untuk ikut Jawaban