tidak bisa update modal dengan jquery

Selamat malam.saya ingin mengupdate data dengan modal melalui jquery.
ini kira-kira kode saya:
<?php
include("koneksi.php");

?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kode Rekening</title>
    <link rel="stylesheet" href="assets/bootstrap-5.0.2-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/jquery/jquery360.js">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="assets/fontawesome620/css/all.css">
    <link rel="stylesheet" href="assets/jquerydatatable/datatables.min.css">
    <link rel="stylesheet" href="assets/jquerydatatable/DataTables-1.12.1/css/dataTables.bootstrap.min.css">
</head>

<body>
    <div class="card">
        <div class="card-header">
            <H6>DATA KODE REKENING</H6>
            <!-- Tombol Tambah KOde Rekening -->
            <button type="button" class="btn btn-success mt-2 btn-sm" data-bs-toggle="modal" data-bs-target="#tambahKodrek"><i class="fa-solid fa-plus"></i> Tambah
            </button>
            <a class="btn btn-info mt-2 btn-sm" type="button" href="kodrek/cetak.php" target="_blank">Cetak Laporan
            </a>
            <a class="btn btn-danger mt-2 btn-sm" type="button" href="kodrek/cetakexcel.php" target="_blank">Cetak Excel
            </a>
        </div>

        <div class="card-body">

            <!-- Awal Tabel KOde Rekening-->
            <table id="tabelKodrek" class="table table-responsive table-stripe table-bordered table-sm compact table-hover row-border">
                <thead class="table-secondary">
                    <tr>
                        <th class="text-center" width="5%">No</th>
                        <th class="text-center" width="5%">Kode 6</th>
                        <th class="text-center" width="25%">Uraian Kode 6</th>
                        <th class="text-center" width="5%">Kode 5</th>
                        <th class="text-center" width="20%">Uraian Kode 5</th>
                        <th class="text-center" width="5%">Kode 2</th>
                        <th class="text-center" width="10%">Uraian Kode 2</th>
                        <th class="text-center" width="5%">Kode 1</th>
                        <th class="text-center" width="10%">Uraian Kode 1</th>
                        <th class="text-center" width="10%">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $no = 1;
                    $data = mysqli_query($koneksi, "SELECT * FROM kodrek ORDER BY kd6 ASC");
                    while ($hasil = mysqli_fetch_array($data)) {
                        echo '
                            <tr>
                                <td class="text-center" width="5%">' . $no++ . '</td>
                                <td class="text-center" width="5%">' . substr($hasil['kd6'], 0, 1) . "."
                            . substr($hasil['kd6'], 1, 1) . "."
                            . substr($hasil['kd6'], 2, 2) . "."
                            . substr($hasil['kd6'], 4, 2) . "."
                            . substr($hasil['kd6'], 6, 2) . "."
                            . substr($hasil['kd6'], 8, 4) . '</td>
                                <td width="25%">' . $hasil['namakd6'] . '</td>
                                <td class="text-center">' . substr($hasil['kd5'], 0, 1) . "."
                            . substr($hasil['kd5'], 1, 1) . "."
                            . substr($hasil['kd5'], 2, 2) . "."
                            . substr($hasil['kd5'], 4, 2) . "."
                            . substr($hasil['kd5'], 6, 2) . '</td>
                                <td>' . $hasil['namakd5'] . '</td>
                                <td class="text-center" width="5%">' . $hasil['kd2'] . '</td>
                                <td>' . $hasil['namakd2'] . '</td>
                                <td class="text-center" width="5%">' . $hasil['kd1'] . '</td>
                                <td>' . $hasil['namakd1'] . '</td>
                                <td class="text-center">
                                <a type="button" class="ubahData" id=' . $hasil['idkd6'] . '> Ubah</a> |
                                <a type="button" id="hapusKodrek">Hapus</a>
                                </td>
                                
                            </tr>
                    ';
                    }
                    ?>

                    <!-- Awal Modal Ubah Kode Rekening-->
                    <div class="modal fade" id="modalubahKodrek" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="ubahKodrekLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <form action="" method="post" id="updateForm">
                                    <div class="modal-header bg-warning">
                                        <h6 class="modal-title" id="ubahKodrekLabel">Ubah Kode Rekening</h6>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body" id="infoUpdate">

                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-success btn-sm" id="updateKodrek"><i class="fa-solid fa-floppy-disk"></i> Update</button>
                                        <button type="button" class="btn btn-danger btn-sm" data-bs-dismiss="modal"><i class="fa-regular fa-circle-xmark"></i> Tutup</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <!-- Akhir Modal Ubah Golongan-->
                </tbody>
            </table>
        </div>
        <!-- Akhir Tabel Golongan-->
    </div>
    </div>
    </div>

    <!-- Awal Modal Tambah Kode Rekening-->
    <div class="modal fade" id="tambahKodrek" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="tambahKodrekLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header bg-success text-white">
                    <h6 class="modal-title" id="tambahKodrekLabel">Tambah Kode Rekening</h6>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form action="kodrek/tambah.php" method="post">
                        <div class="mb-3">
                            <label for="idkd6" class="form-label" hidden>Id Kode Belanja</label>
                            <input type="text" class="form-control form-control-sm" id="idkd6" name="idkd6" placeholder="ID Kode 6" hidden>
                        </div>
                        <div class="mb-3">
                            <label for="kd6" class="form-label">Kode Belanja 6</label>
                            <input type="text" class="form-control form-control-sm" id="kd6" name="kd6" placeholder="Kode Belanja 6" maxlength="12" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd6" class="form-label">Uraian Kode Belanja 6</label>
                            <input type="text" class="form-control form-control-sm" id="namakd6" name="namakd6" placeholder="Uraian Kode Belanja 6" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd5" class="form-label">Kode Belanja 5</label>
                            <input type="text" class="form-control form-control-sm" id="kd5" name="kd5" placeholder="Kode Belanja 5" maxlength="8" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd5" class="form-label">Uraian Kode Belanja 5</label>
                            <input type="text" class="form-control form-control-sm" id="namakd5" name="namakd5" placeholder="Uraian Kode Belanja 5" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd4" class="form-label">Kode Belanja 4</label>
                            <input type="text" class="form-control form-control-sm" id="kd4" name="kd4" placeholder="Kode Belanja 4" maxlength="6" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd4" class="form-label">Uraian Kode Belanja 4</label>
                            <input type="text" class="form-control form-control-sm" id="namakd4" name="namakd4" placeholder="Uraian Kode Belanja 4" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd3" class="form-label">Kode Belanja 3</label>
                            <input type="text" class="form-control form-control-sm" id="kd3" name="kd3" placeholder="Kode Belanja 3" maxlength="4" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd3" class="form-label">Uraian Kode Belanja 3</label>
                            <input type="text" class="form-control form-control-sm" id="namakd3" name="namakd3" placeholder="Uraian Kode Belanja 3" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd2" class="form-label">Kode Belanja 2</label>
                            <input type="text" class="form-control form-control-sm" id="kd2" name="kd2" placeholder="Kode Belanja 2" maxlength="2" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd2" class="form-label">Uraian Kode Belanja 2</label>
                            <input type="text" class="form-control form-control-sm" id="namakd2" name="namakd2" placeholder="Uraian Kode Belanja 2" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd1" class="form-label">Kode Belanja 1</label>
                            <input type="text" class="form-control form-control-sm" id="kd1" name="kd1" placeholder="Kode Belanja 1" maxlength="1" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd1" class="form-label">Uraian Kode Belanja 1</label>
                            <input type="text" class="form-control form-control-sm" id="namakd1" name="namakd1" placeholder="Uraian Kode Belanja 1" required>
                        </div>
                        <button type="submit" class="btn btn-success btn-sm" name="simpanKodrek"><i class="fa-solid fa-floppy-disk"></i> Simpan</button>
                        <button type="reset" class="btn btn-warning btn-sm"><i class="fa-solid fa-ban"></i> Batal</button>
                        <button type="button" class="btn btn-danger btn-sm" data-bs-dismiss="modal"><i class="fa-regular fa-circle-xmark"></i> Tutup</button>
                    </form>
                </div>
                <div class="modal-footer">
                </div>
            </div>
        </div>
    </div>
    <!-- Akhir Modal Tambah Kode Rekening-->

    <script type="text/javascript" src="assets/bootstrap-5.0.2-dist/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="assets/jquery/jquery360.js"></script>
    <script type="text/javascript" src="assets/jquery/tools.js"></script>
    <script type="text/javascript" src="assets/jquerydatatable/datatables.min.js"></script>
    <script type="text/javascript" src="assets/jquerydatatable/DataTables-1.12.1/js/dataTables.bootstrap.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#tabelKodrek").DataTable();


            //script update
            $(document).on('click', '.ubahData', function() {
                var edit_id = $(this).attr('id');
                $.ajax({
                    url: 'kodrek/ubah.php',
                    type: 'post',
                    data: {
                        edit_id: edit_id
                    },
                    success: function(data) {
                        $('#infoUpdate').html(data);
                        $('modalubahKodrek').modal('show');
                    }
                });
                $('#modalubahKodrek').modal('show');
            });
            //end script update


            //script simpan update
            $(document).on('click', '#updateKodrek', function() {
                $.ajax({
                    url: 'kodrek/simpanubah.php',
                    type: 'post',
                    data: $('#updateForm').serialize(),
                    success: function(data) {
                        $('#modalubahKodrek').modal('hide');
                        location.reload();
                    }
                });

            });
            //akhir script simpan update

            $('#hapusKodrek').click(function() {
                alert('Apakah Anda Yakin Akan Menghapus Data..........?');
            });
        });
    </script>
</body>

</html>

ini script ubah.php
<?php
include("../koneksi.php");

if (isset($_POST['edit_id'])) {

    $idkd6 = $_POST['edit_id'];
    $query = mysqli_query($koneksi, "SELECT * FROM kodrek WHERE idkd6 = '$idkd6'");
    while ($row = mysqli_fetch_array($query)) {
        $idkd6      = $row['idkd6'];
        $kd6        = $row['kd6'];
        $namakd6    = $row['namakd6'];
        $kd5      = $row['kd5'];
        $namakd5    = $row['namakd5'];
        $kd4      = $row['kd4'];
        $namakd4    = $row['namakd4'];
        $kd3      = $row['kd3'];
        $namakd3    = $row['namakd3'];
        $kd2      = $row['kd2'];
        $namakd2    = $row['namakd2'];
        $kd1      = $row['kd1'];
        $namakd1    = $row['namakd1'];
    }
}
?>

<input type="text" class="form-control form-control-sm" id="edit_id" name="edit_id" value="<?php echo $idkd6 ?>" readonly>

<label for="kd6" class="form-label">Kode Belanja 6</label>
<input type="text" class="form-control form-control-sm" id="kd6" name="kd6" placeholder="Kode Belanja 6" maxlength="12" required value="<?php echo $kd6 ?>">

<label for="namakd6" class="form-label">Uraian Kode Belanja 6</label>
<input type="text" class="form-control form-control-sm" id="namakd6" name="namakd6" placeholder="Uraian Kode Belanja 6" required value="<?php echo $namakd6 ?>">

<label for="kd5" class="form-label">Kode Belanja 5</label>
<input type="text" class="form-control form-control-sm" id="kd5" name="kd5" placeholder="Kode Belanja 5" maxlength="8" required value="<?php echo $kd5 ?>">

<label for="namakd5" class="form-label">Uraian Kode Belanja 5</label>
<input type="text" class="form-control form-control-sm" id="namakd5" name="namakd5" placeholder="Uraian Kode Belanja 5" required value="<?php echo $namakd5 ?>">

<label for="kd4" class="form-label">Kode Belanja 4</label>
<input type="text" class="form-control form-control-sm" id="kd4" name="kd4" placeholder="Kode Belanja 4" maxlength="8" required value="<?php echo $kd4 ?>">

<label for="namakd4" class="form-label">Uraian Kode Belanja 4</label>
<input type="text" class="form-control form-control-sm" id="namakd4" name="namakd4" placeholder="Uraian Kode Belanja 4" required value="<?php echo $namakd4 ?>">

<label for="kd3" class="form-label">Kode Belanja 3</label>
<input type="text" class="form-control form-control-sm" id="kd3" name="kd3" placeholder="Kode Belanja 3" maxlength="8" required value="<?php echo $kd3 ?>">

<label for="namakd3" class="form-label">Uraian Kode Belanja 3</label>
<input type="text" class="form-control form-control-sm" id="namakd3" name="namakd3" placeholder="Uraian Kode Belanja 3" required value="<?php echo $namakd3 ?>">

<label for="kd2" class="form-label">Kode Belanja 2</label>
<input type="text" class="form-control form-control-sm" id="kd2" name="kd2" placeholder="Kode Belanja 2" maxlength="8" required value="<?php echo $kd2 ?>">

<label for="namakd2" class="form-label">Uraian Kode Belanja 2</label>
<input type="text" class="form-control form-control-sm" id="namakd2" name="namakd2" placeholder="Uraian Kode Belanja 2" required value="<?php echo $namakd2 ?>">

<label for="kd1" class="form-label">Kode Belanja 1</label>
<input type="text" class="form-control form-control-sm" id="kd1" name="kd1" placeholder="Kode Belanja 1" maxlength="8" required value="<?php echo $kd1 ?>">

<label for="namakd1" class="form-label">Uraian Kode Belanja 1</label>
<input type="text" class="form-control form-control-sm" id="namakd1" name="namakd1" placeholder="Uraian Kode Belanja 1" required value="<?php echo $namakd1 ?>">


ini script simpanubah.php
<?php
include("koneksi.php");

$idkd6      = $_POST['idkd6'];
$kd6        = $_POST['kd6'];
$namakd6    = $_POST['namakd6'];
$kd5        = $_POST['kd5'];
$namakd5    = $_POST['namakd5'];
$kd4        = $_POST['kd4'];
$namakd4    = $_POST['namakd4'];
$kd3        = $_POST['kd3'];
$namakd3    = $_POST['namakd3'];
$kd2        = $_POST['kd2'];
$namakd2    = $_POST['namakd2'];
$kd1        = $_POST['kd1'];
$namakd1    = $_POST['namakd1'];

$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");

pada saat klik tmbol ubah,data masuk ke modal edit.tapi saat di simpan,tidak ada data yang ter update.mohon bantuannya.








avatar ruben46

@ruben46

17 Kontribusi 0 Poin


Jawaban

Pasti sudah ketemu jawabannya ya kalo sekarang?

//Bagian form mu

$idkd6      = $_POST['idkd6']; //<-------
$kd6        = $_POST['kd6'];
$namakd6    = $_POST['namakd6'];

//Bagian simpanubah.php
<input type="text" class="form-control form-control-sm" id="edit_id" name="edit_id" value="<?php echo $idkd6 ?>" readonly>


Yang ada [name='edit_id'] dan bukan [name='idkd6']



avatar GrennKren

@GrennKren

61 Kontribusi 45 Poin

  • di samain jga masih sama kak.tidak bisa terupdate. - @ruben46


masih sama kak.di samain nilainya pun tetap gak bisa ke update

<?php
include("koneksi.php");

?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kode Rekening</title>
    <link rel="stylesheet" href="assets/bootstrap-5.0.2-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/jquery/jquery360.js">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="assets/fontawesome620/css/all.css">
    <link rel="stylesheet" href="assets/jquerydatatable/datatables.min.css">
    <link rel="stylesheet" href="assets/jquerydatatable/DataTables-1.12.1/css/dataTables.bootstrap.min.css">
</head>

<body>
    <div class="card">
        <div class="card-header">
            <H6>DATA KODE REKENING</H6>
            <!-- Tombol Tambah KOde Rekening -->
            <button type="button" class="btn btn-success mt-2 btn-sm" data-bs-toggle="modal" data-bs-target="#tambahKodrek"><i class="fa-solid fa-plus"></i> Tambah
            </button>
            <a class="btn btn-info mt-2 btn-sm" type="button" href="kodrek/cetak.php" target="_blank">Cetak Laporan
            </a>
            <a class="btn btn-danger mt-2 btn-sm" type="button" href="kodrek/cetakexcel.php" target="_blank">Cetak Excel
            </a>
        </div>

        <div class="card-body">

            <!-- Awal Tabel KOde Rekening-->
            <table id="tabelKodrek" class="table table-responsive table-stripe table-bordered table-sm compact table-hover row-border">
                <thead class="table-secondary">
                    <tr>
                        <th class="text-center" width="5%">No</th>
                        <th class="text-center" width="5%">Kode 6</th>
                        <th class="text-center" width="25%">Uraian Kode 6</th>
                        <th class="text-center" width="5%">Kode 5</th>
                        <th class="text-center" width="20%">Uraian Kode 5</th>
                        <th class="text-center" width="5%">Kode 2</th>
                        <th class="text-center" width="10%">Uraian Kode 2</th>
                        <th class="text-center" width="5%">Kode 1</th>
                        <th class="text-center" width="10%">Uraian Kode 1</th>
                        <th class="text-center" width="10%">Aksi</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    $no = 1;
                    $data = mysqli_query($koneksi, "SELECT * FROM kodrek ORDER BY kd6 ASC");
                    while ($hasil = mysqli_fetch_array($data)) {
                        echo '
                            <tr>
                                <td class="text-center" width="5%">' . $no++ . '</td>
                                <td class="text-center" width="5%">' . substr($hasil['kd6'], 0, 1) . "."
                            . substr($hasil['kd6'], 1, 1) . "."
                            . substr($hasil['kd6'], 2, 2) . "."
                            . substr($hasil['kd6'], 4, 2) . "."
                            . substr($hasil['kd6'], 6, 2) . "."
                            . substr($hasil['kd6'], 8, 4) . '</td>
                                <td width="25%">' . $hasil['namakd6'] . '</td>
                                <td class="text-center">' . substr($hasil['kd5'], 0, 1) . "."
                            . substr($hasil['kd5'], 1, 1) . "."
                            . substr($hasil['kd5'], 2, 2) . "."
                            . substr($hasil['kd5'], 4, 2) . "."
                            . substr($hasil['kd5'], 6, 2) . '</td>
                                <td>' . $hasil['namakd5'] . '</td>
                                <td class="text-center" width="5%">' . $hasil['kd2'] . '</td>
                                <td>' . $hasil['namakd2'] . '</td>
                                <td class="text-center" width="5%">' . $hasil['kd1'] . '</td>
                                <td>' . $hasil['namakd1'] . '</td>
                                <td class="text-center">
                                <a type="button" class="ubahData" id=' . $hasil['idkd6'] . '> Ubah</a> |
                                <a type="button" id="hapusKodrek">Hapus</a>
                                </td>
                                
                            </tr>
                    ';
                    }
                    ?>

                    <!-- Awal Modal Ubah Kode Rekening-->
                    <div class="modal fade" id="modalubahKodrek" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="ubahKodrekLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <form action="" method="post" id="updateForm">
                                    <div class="modal-header bg-warning">
                                        <h6 class="modal-title" id="ubahKodrekLabel">Ubah Kode Rekening</h6>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <div class="modal-body" id="infoUpdate">

                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-success btn-sm" id="updateKodrek"><i class="fa-solid fa-floppy-disk"></i> Update</button>
                                        <button type="button" class="btn btn-danger btn-sm" data-bs-dismiss="modal"><i class="fa-regular fa-circle-xmark"></i> Tutup</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <!-- Akhir Modal Ubah Golongan-->
                </tbody>
            </table>
        </div>
        <!-- Akhir Tabel Golongan-->
    </div>
    </div>
    </div>

    <!-- Awal Modal Tambah Kode Rekening-->
    <div class="modal fade" id="tambahKodrek" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="tambahKodrekLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header bg-success text-white">
                    <h6 class="modal-title" id="tambahKodrekLabel">Tambah Kode Rekening</h6>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <form action="kodrek/tambah.php" method="post">
                        <div class="mb-3">
                            <label for="idkd6" class="form-label" hidden>Id Kode Belanja</label>
                            <input type="text" class="form-control form-control-sm" id="idkd6" name="idkd6" placeholder="ID Kode 6" hidden>
                        </div>
                        <div class="mb-3">
                            <label for="kd6" class="form-label">Kode Belanja 6</label>
                            <input type="text" class="form-control form-control-sm" id="kd6" name="kd6" placeholder="Kode Belanja 6" maxlength="12" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd6" class="form-label">Uraian Kode Belanja 6</label>
                            <input type="text" class="form-control form-control-sm" id="namakd6" name="namakd6" placeholder="Uraian Kode Belanja 6" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd5" class="form-label">Kode Belanja 5</label>
                            <input type="text" class="form-control form-control-sm" id="kd5" name="kd5" placeholder="Kode Belanja 5" maxlength="8" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd5" class="form-label">Uraian Kode Belanja 5</label>
                            <input type="text" class="form-control form-control-sm" id="namakd5" name="namakd5" placeholder="Uraian Kode Belanja 5" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd4" class="form-label">Kode Belanja 4</label>
                            <input type="text" class="form-control form-control-sm" id="kd4" name="kd4" placeholder="Kode Belanja 4" maxlength="6" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd4" class="form-label">Uraian Kode Belanja 4</label>
                            <input type="text" class="form-control form-control-sm" id="namakd4" name="namakd4" placeholder="Uraian Kode Belanja 4" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd3" class="form-label">Kode Belanja 3</label>
                            <input type="text" class="form-control form-control-sm" id="kd3" name="kd3" placeholder="Kode Belanja 3" maxlength="4" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd3" class="form-label">Uraian Kode Belanja 3</label>
                            <input type="text" class="form-control form-control-sm" id="namakd3" name="namakd3" placeholder="Uraian Kode Belanja 3" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd2" class="form-label">Kode Belanja 2</label>
                            <input type="text" class="form-control form-control-sm" id="kd2" name="kd2" placeholder="Kode Belanja 2" maxlength="2" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd2" class="form-label">Uraian Kode Belanja 2</label>
                            <input type="text" class="form-control form-control-sm" id="namakd2" name="namakd2" placeholder="Uraian Kode Belanja 2" required>
                        </div>
                        <div class="mb-3">
                            <label for="kd1" class="form-label">Kode Belanja 1</label>
                            <input type="text" class="form-control form-control-sm" id="kd1" name="kd1" placeholder="Kode Belanja 1" maxlength="1" required>
                        </div>
                        <div class="mb-3">
                            <label for="namakd1" class="form-label">Uraian Kode Belanja 1</label>
                            <input type="text" class="form-control form-control-sm" id="namakd1" name="namakd1" placeholder="Uraian Kode Belanja 1" required>
                        </div>
                        <button type="submit" class="btn btn-success btn-sm" name="simpanKodrek"><i class="fa-solid fa-floppy-disk"></i> Simpan</button>
                        <button type="reset" class="btn btn-warning btn-sm"><i class="fa-solid fa-ban"></i> Batal</button>
                        <button type="button" class="btn btn-danger btn-sm" data-bs-dismiss="modal"><i class="fa-regular fa-circle-xmark"></i> Tutup</button>
                    </form>
                </div>
                <div class="modal-footer">
                </div>
            </div>
        </div>
    </div>
    <!-- Akhir Modal Tambah Kode Rekening-->

    <script type="text/javascript" src="assets/bootstrap-5.0.2-dist/js/bootstrap.bundle.min.js"></script>
    <script type="text/javascript" src="assets/jquery/jquery360.js"></script>
    <script type="text/javascript" src="assets/jquery/tools.js"></script>
    <script type="text/javascript" src="assets/jquerydatatable/datatables.min.js"></script>
    <script type="text/javascript" src="assets/jquerydatatable/DataTables-1.12.1/js/dataTables.bootstrap.min.js"></script>
    <script>
        $(document).ready(function() {
            $("#tabelKodrek").DataTable();


            //script update
            $(document).on('click', '.ubahData', function() {
                var edit_id = $(this).attr('id');
                $.ajax({
                    url: 'kodrek/ubah.php',
                    type: 'post',
                    data: {
                        edit_id: edit_id
                    },
                    success: function(data) {
                        $('#infoUpdate').html(data);
                        $('modalubahKodrek').modal('show');
                    }
                });
                $('#modalubahKodrek').modal('show');
            });
            //end script update


            //script simpan update
            $(document).on('click', '#updateKodrek', function() {
                $.ajax({
                    url: 'kodrek/simpanubah.php',
                    type: 'post',
                    data: $('#updateForm').serialize(),
                    success: function(data) {
                        $('#modalubahKodrek').modal('hide');
                        location.reload();
                    }
                });

            });
            //akhir script simpan update

            $('#hapusKodrek').click(function() {
                alert('Apakah Anda Yakin Akan Menghapus Data..........?');
            });
        });
    </script>
</body>

</html>

script ubah.php

<?php
include("../koneksi.php");

if (isset($_POST['edit_id'])) {

    $idkd6 = $_POST['edit_id'];
    $query = mysqli_query($koneksi, "SELECT * FROM kodrek WHERE idkd6 = '$idkd6'");
    while ($row = mysqli_fetch_array($query)) {
        $idkd6      = $row['idkd6'];
        $kd6        = $row['kd6'];
        $namakd6    = $row['namakd6'];
        $kd5      = $row['kd5'];
        $namakd5    = $row['namakd5'];
        $kd4      = $row['kd4'];
        $namakd4    = $row['namakd4'];
        $kd3      = $row['kd3'];
        $namakd3    = $row['namakd3'];
        $kd2      = $row['kd2'];
        $namakd2    = $row['namakd2'];
        $kd1      = $row['kd1'];
        $namakd1    = $row['namakd1'];
    }
}
?>

<input type="text" class="form-control form-control-sm" id="idkd6" name="idkd6" value="<?php echo $idkd6 ?>" readonly>

<label for="kd6" class="form-label">Kode Belanja 6</label>
<input type="text" class="form-control form-control-sm" id="kd6" name="kd6" placeholder="Kode Belanja 6" maxlength="12" required value="<?php echo $kd6 ?>">

<label for="namakd6" class="form-label">Uraian Kode Belanja 6</label>
<input type="text" class="form-control form-control-sm" id="namakd6" name="namakd6" placeholder="Uraian Kode Belanja 6" required value="<?php echo $namakd6 ?>">

<label for="kd5" class="form-label">Kode Belanja 5</label>
<input type="text" class="form-control form-control-sm" id="kd5" name="kd5" placeholder="Kode Belanja 5" maxlength="8" required value="<?php echo $kd5 ?>">

<label for="namakd5" class="form-label">Uraian Kode Belanja 5</label>
<input type="text" class="form-control form-control-sm" id="namakd5" name="namakd5" placeholder="Uraian Kode Belanja 5" required value="<?php echo $namakd5 ?>">

<label for="kd4" class="form-label">Kode Belanja 4</label>
<input type="text" class="form-control form-control-sm" id="kd4" name="kd4" placeholder="Kode Belanja 4" maxlength="8" required value="<?php echo $kd4 ?>">

<label for="namakd4" class="form-label">Uraian Kode Belanja 4</label>
<input type="text" class="form-control form-control-sm" id="namakd4" name="namakd4" placeholder="Uraian Kode Belanja 4" required value="<?php echo $namakd4 ?>">

<label for="kd3" class="form-label">Kode Belanja 3</label>
<input type="text" class="form-control form-control-sm" id="kd3" name="kd3" placeholder="Kode Belanja 3" maxlength="8" required value="<?php echo $kd3 ?>">

<label for="namakd3" class="form-label">Uraian Kode Belanja 3</label>
<input type="text" class="form-control form-control-sm" id="namakd3" name="namakd3" placeholder="Uraian Kode Belanja 3" required value="<?php echo $namakd3 ?>">

<label for="kd2" class="form-label">Kode Belanja 2</label>
<input type="text" class="form-control form-control-sm" id="kd2" name="kd2" placeholder="Kode Belanja 2" maxlength="8" required value="<?php echo $kd2 ?>">

<label for="namakd2" class="form-label">Uraian Kode Belanja 2</label>
<input type="text" class="form-control form-control-sm" id="namakd2" name="namakd2" placeholder="Uraian Kode Belanja 2" required value="<?php echo $namakd2 ?>">

<label for="kd1" class="form-label">Kode Belanja 1</label>
<input type="text" class="form-control form-control-sm" id="kd1" name="kd1" placeholder="Kode Belanja 1" maxlength="8" required value="<?php echo $kd1 ?>">

<label for="namakd1" class="form-label">Uraian Kode Belanja 1</label>
<input type="text" class="form-control form-control-sm" id="namakd1" name="namakd1" placeholder="Uraian Kode Belanja 1" required value="<?php echo $namakd1 ?>">


script simpanubah.php

<?php
include("koneksi.php");

$idkd6      = $_POST['idkd6'];
$kd6        = $_POST['kd6'];
$namakd6    = $_POST['namakd6'];
$kd5        = $_POST['kd5'];
$namakd5    = $_POST['namakd5'];
$kd4        = $_POST['kd4'];
$namakd4    = $_POST['namakd4'];
$kd3        = $_POST['kd3'];
$namakd3    = $_POST['namakd3'];
$kd2        = $_POST['kd2'];
$namakd2    = $_POST['namakd2'];
$kd1        = $_POST['kd1'];
$namakd1    = $_POST['namakd1'];

$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");


tapi anehnya,saat mncul modal ubah,semua nilai ada di form ubahnya

image.pngimage.png
mohon pencerahannya kak.maaf saya baru belajar

avatar ruben46

@ruben46

17 Kontribusi 0 Poin


Tadi aku mengira karena tombol button nya tapi rupanya bukan.

Kalau gitu ya coba aja lakukan debug di query nya.
Jika lewat DevTools browser. Tekan tombol F12 biasanya untuk chrome dan Firefox. lalu di bagian tab network nya itu bakal keliatan proses ajax nya ketika kita nekan tombol di form.

Tapi pastikan di centang "Preserve Log" karena di ajax mu ada perintah location.reload , yang mana jika halaman ke refresh yg di DevTools bakal ikutan ke reset.

===============

Kalau pengen lewat koding, di dalam fileΒ  kodrek/simpanubah.php mu, di akhirnya tambahin
if(!$sql){
   echo "Terjadi kesalahan : " . mysqli_error($koneksi);
}

Lalu di ajax yang bersangkutan
$(document).on('click', '#updateKodrek', function(event) {
  event.preventDefault(); //<---------
  $.ajax({
    url: 'kodrek/simpanubah.php',
    type: 'post',
    data: $('#updateForm').serialize(),
    success: function(data) { <---------
       if(data.length > 0){   
          alert(data)         
       }else{
          $('#modalubahKodrek').modal('hide');
          location.reload();
       }
    }
  });
});

Fungsinya buat mengecek jika kodrek/simpanubah.php ada yang di echo, maka di manggil apa isi nya melalui alert(data)
avatar GrennKren

@GrennKren

61 Kontribusi 45 Poin

  • masih sama kak.saya masukin kodingnya jg gak ada alert yg mncul - @ruben46



script tmbol

 $(document).on('click', '#updateKodrek', function() {
                event.preventDefault();
                $.ajax({
                    url: 'kodrek/simpanubah.php',
                    type: 'post',
                    data: $('#updateForm').serialize(),
                    success: function(data) {
                        $('#modalubahKodrek').modal('hide');
                        location.reload();
                    }
                });

            });

script simpanubah.php

 <?php
include("koneksi.php");

$idkd6      = $_POST['idkd6'];
$kd6        = $_POST['kd6'];
$namakd6    = $_POST['namakd6'];
$kd5        = $_POST['kd5'];
$namakd5    = $_POST['namakd5'];
$kd4        = $_POST['kd4'];
$namakd4    = $_POST['namakd4'];
$kd3        = $_POST['kd3'];
$namakd3    = $_POST['namakd3'];
$kd2        = $_POST['kd2'];
$namakd2    = $_POST['namakd2'];
$kd1        = $_POST['kd1'];
$namakd1    = $_POST['namakd1'];

$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");

if(!$sql){
    echo "Terjadi Kesalahan : " . mysqli_error($koneksi);
}

ss debug

image.pngimage.png



avatar ruben46

@ruben46

17 Kontribusi 0 Poin

  • Kamu ga ada parameter event di dalam ('click', '#updateKodrek', function(event) - @GrennKren
  • jadinya terjadi error dan terhenti sebelum menjalakankan ajax. - @GrennKren
  • Atau hapus aja baris event.PreventDefault, soalnya ga ada hubungan nya ternyata ama kendalanya - @GrennKren


Kalau sudah di hapus event.preventDefault nya.
$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");

echo "test"; //<-------

if(!$sql){
    echo "Terjadi Kesalahan : " . mysqli_error($koneksi);
}

Bukan cara yang cantik, cuman memastikan aja jika yang diubah beneran file yang dimaksud dan bisa ditangkep melalui ajax.
avatar GrennKren

@GrennKren

61 Kontribusi 45 Poin

  • masih sama kak,saya masukin line echonya,saat klik simpan,gak muncul tulisan testnya.maaf ya kak saya banyak nanya. - @ruben46


ini hasil scriptnya

$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");

echo "test";

if(!$sql){
    echo "Terjadi Kesalahan : " . mysqli_error($koneksi);
}

avatar ruben46

@ruben46

17 Kontribusi 0 Poin

  • ya gak bisa ngeliat alert nya soalnya ajax mu kan belum diubah. gak ada pengecekan data.length > 0 - @GrennKren


Login untuk gabung berdiskusi