Postingan lainnya
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.
6 Jawaban:
<div>Pasti sudah ketemu jawabannya ya kalo sekarang?<br><br></div><pre>//Bagian form mu
$idkd6 = $_POST['idkd6']; //<------- $kd6 = $_POST['kd6']; $namakd6 = $_POST['namakd6'];
//Bagian simpanubah.php<pre><input type="text" class="form-control form-control-sm" id="edit_id" name="edit_id" value="<?php echo $idkd6 ?>" readonly></pre></pre><div><br></div><div><br>Yang ada [name='edit_id'] dan bukan [name='idkd6']</div><div><br></div><div><br></div><div><br><br></div>
Tanggapan
di samain jga masih sama kak.tidak bisa terupdate.
<div>masih sama kak.di samain nilainya pun tetap gak bisa ke update<br><br></div><pre><?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>
&lt;div class="card-body"&gt;
&lt;!-- Awal Tabel KOde Rekening--&gt;
&lt;table id="tabelKodrek" class="table table-responsive table-stripe table-bordered table-sm compact table-hover row-border"&gt;
&lt;thead class="table-secondary"&gt;
&lt;tr&gt;
&lt;th class="text-center" width="5%"&gt;No&lt;/th&gt;
&lt;th class="text-center" width="5%"&gt;Kode 6&lt;/th&gt;
&lt;th class="text-center" width="25%"&gt;Uraian Kode 6&lt;/th&gt;
&lt;th class="text-center" width="5%"&gt;Kode 5&lt;/th&gt;
&lt;th class="text-center" width="20%"&gt;Uraian Kode 5&lt;/th&gt;
&lt;th class="text-center" width="5%"&gt;Kode 2&lt;/th&gt;
&lt;th class="text-center" width="10%"&gt;Uraian Kode 2&lt;/th&gt;
&lt;th class="text-center" width="5%"&gt;Kode 1&lt;/th&gt;
&lt;th class="text-center" width="10%"&gt;Uraian Kode 1&lt;/th&gt;
&lt;th class="text-center" width="10%"&gt;Aksi&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;?php
$no = 1;
$data = mysqli_query($koneksi, "SELECT * FROM kodrek ORDER BY kd6 ASC");
while ($hasil = mysqli_fetch_array($data)) {
echo '
&lt;tr&gt;
&lt;td class="text-center" width="5%"&gt;' . $no++ . '&lt;/td&gt;
&lt;td class="text-center" width="5%"&gt;' . 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) . '&lt;/td&gt;
&lt;td width="25%"&gt;' . $hasil['namakd6'] . '&lt;/td&gt;
&lt;td class="text-center"&gt;' . 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) . '&lt;/td&gt;
&lt;td&gt;' . $hasil['namakd5'] . '&lt;/td&gt;
&lt;td class="text-center" width="5%"&gt;' . $hasil['kd2'] . '&lt;/td&gt;
&lt;td&gt;' . $hasil['namakd2'] . '&lt;/td&gt;
&lt;td class="text-center" width="5%"&gt;' . $hasil['kd1'] . '&lt;/td&gt;
&lt;td&gt;' . $hasil['namakd1'] . '&lt;/td&gt;
&lt;td class="text-center"&gt;
&lt;a type="button" class="ubahData" id=' . $hasil['idkd6'] . '&gt; Ubah&lt;/a&gt; |
&lt;a type="button" id="hapusKodrek"&gt;Hapus&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
';
}
?&gt;
&lt;!-- Awal Modal Ubah Kode Rekening--&gt;
&lt;div class="modal fade" id="modalubahKodrek" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="ubahKodrekLabel" aria-hidden="true"&gt;
&lt;div class="modal-dialog"&gt;
&lt;div class="modal-content"&gt;
&lt;form action="" method="post" id="updateForm"&gt;
&lt;div class="modal-header bg-warning"&gt;
&lt;h6 class="modal-title" id="ubahKodrekLabel"&gt;Ubah Kode Rekening&lt;/h6&gt;
&lt;button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"&gt;&lt;/button&gt;
&lt;/div&gt;
&lt;div class="modal-body" id="infoUpdate"&gt;
&lt;/div&gt;
&lt;div class="modal-footer"&gt;
&lt;button type="button" class="btn btn-success btn-sm" id="updateKodrek"&gt;&lt;i class="fa-solid fa-floppy-disk"&gt;&lt;/i&gt; Update&lt;/button&gt;
&lt;button type="button" class="btn btn-danger btn-sm" data-bs-dismiss="modal"&gt;&lt;i class="fa-regular fa-circle-xmark"&gt;&lt;/i&gt; Tutup&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- Akhir Modal Ubah Golongan--&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;!-- Akhir Tabel Golongan--&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- Awal Modal Tambah Kode Rekening--&gt;
&lt;div class="modal fade" id="tambahKodrek" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="tambahKodrekLabel" aria-hidden="true"&gt;
&lt;div class="modal-dialog"&gt;
&lt;div class="modal-content"&gt;
&lt;div class="modal-header bg-success text-white"&gt;
&lt;h6 class="modal-title" id="tambahKodrekLabel"&gt;Tambah Kode Rekening&lt;/h6&gt;
&lt;button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"&gt;&lt;/button&gt;
&lt;/div&gt;
&lt;div class="modal-body"&gt;
&lt;form action="kodrek/tambah.php" method="post"&gt;
&lt;div class="mb-3"&gt;
&lt;label for="idkd6" class="form-label" hidden&gt;Id Kode Belanja&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="idkd6" name="idkd6" placeholder="ID Kode 6" hidden&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="kd6" class="form-label"&gt;Kode Belanja 6&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="kd6" name="kd6" placeholder="Kode Belanja 6" maxlength="12" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="namakd6" class="form-label"&gt;Uraian Kode Belanja 6&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="namakd6" name="namakd6" placeholder="Uraian Kode Belanja 6" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="kd5" class="form-label"&gt;Kode Belanja 5&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="kd5" name="kd5" placeholder="Kode Belanja 5" maxlength="8" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="namakd5" class="form-label"&gt;Uraian Kode Belanja 5&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="namakd5" name="namakd5" placeholder="Uraian Kode Belanja 5" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="kd4" class="form-label"&gt;Kode Belanja 4&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="kd4" name="kd4" placeholder="Kode Belanja 4" maxlength="6" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="namakd4" class="form-label"&gt;Uraian Kode Belanja 4&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="namakd4" name="namakd4" placeholder="Uraian Kode Belanja 4" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="kd3" class="form-label"&gt;Kode Belanja 3&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="kd3" name="kd3" placeholder="Kode Belanja 3" maxlength="4" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="namakd3" class="form-label"&gt;Uraian Kode Belanja 3&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="namakd3" name="namakd3" placeholder="Uraian Kode Belanja 3" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="kd2" class="form-label"&gt;Kode Belanja 2&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="kd2" name="kd2" placeholder="Kode Belanja 2" maxlength="2" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="namakd2" class="form-label"&gt;Uraian Kode Belanja 2&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="namakd2" name="namakd2" placeholder="Uraian Kode Belanja 2" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="kd1" class="form-label"&gt;Kode Belanja 1&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="kd1" name="kd1" placeholder="Kode Belanja 1" maxlength="1" required&gt;
&lt;/div&gt;
&lt;div class="mb-3"&gt;
&lt;label for="namakd1" class="form-label"&gt;Uraian Kode Belanja 1&lt;/label&gt;
&lt;input type="text" class="form-control form-control-sm" id="namakd1" name="namakd1" placeholder="Uraian Kode Belanja 1" required&gt;
&lt;/div&gt;
&lt;button type="submit" class="btn btn-success btn-sm" name="simpanKodrek"&gt;&lt;i class="fa-solid fa-floppy-disk"&gt;&lt;/i&gt; Simpan&lt;/button&gt;
&lt;button type="reset" class="btn btn-warning btn-sm"&gt;&lt;i class="fa-solid fa-ban"&gt;&lt;/i&gt; Batal&lt;/button&gt;
&lt;button type="button" class="btn btn-danger btn-sm" data-bs-dismiss="modal"&gt;&lt;i class="fa-regular fa-circle-xmark"&gt;&lt;/i&gt; Tutup&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;div class="modal-footer"&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- Akhir Modal Tambah Kode Rekening--&gt;
&lt;script type="text/javascript" src="assets/bootstrap-5.0.2-dist/js/bootstrap.bundle.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="assets/jquery/jquery360.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="assets/jquery/tools.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="assets/jquerydatatable/datatables.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="assets/jquerydatatable/DataTables-1.12.1/js/dataTables.bootstrap.min.js"&gt;&lt;/script&gt;
&lt;script&gt;
$(document).ready(<em>function</em>() {
$("#tabelKodrek").DataTable();
//script update
$(document).on('click', '.ubahData', <em>function</em>() {
<em>var</em> edit_id = $(this).attr('id');
$.ajax({
url: 'kodrek/ubah.php',
type: 'post',
data: {
edit_id: edit_id
},
success: <em>function</em>(<em>data</em>) {
$('#infoUpdate').html(data);
$('modalubahKodrek').modal('show');
}
});
$('#modalubahKodrek').modal('show');
});
//end script update
//script simpan update
$(document).on('click', '#updateKodrek', <em>function</em>() {
$.ajax({
url: 'kodrek/simpanubah.php',
type: 'post',
data: $('#updateForm').serialize(),
success: <em>function</em>(<em>data</em>) {
$('#modalubahKodrek').modal('hide');
location.reload();
}
});
});
//akhir script simpan update
$('#hapusKodrek').click(<em>function</em>() {
alert('Apakah Anda Yakin Akan Menghapus Data..........?');
});
});
&lt;/script&gt;
</body>
</html></pre><div><br>script ubah.php<br><br></div><pre><?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 ?>"> <br></pre><div><br>script simpanubah.php<br><br></div><pre><?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."'"); <br></pre><div><br>tapi anehnya,saat mncul modal ubah,semua nilai ada di form ubahnya<br><br><figure data-trix-attachment="{"contentType":"image/png","filename":"image.png","filesize":29254,"height":843,"url":"https://i.ibb.co/GxvQwzQ/image.png","width":619}" data-trix-content-type="image/png" data-trix-attributes="{"presentation":"gallery"}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/GxvQwzQ/image.png" width="619" height="843"><figcaption class="attachment__caption"><span class="attachment__name">image.png</span></figcaption></figure><br>mohon pencerahannya kak.maaf saya baru belajar<br><br></div>
<div>Tadi aku mengira karena tombol button nya tapi rupanya bukan.<br><br>Kalau gitu ya coba aja lakukan debug di query nya.<br>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.<br><br>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.<br><br>===============<br><br>Kalau pengen lewat koding, di dalam file kodrek/simpanubah.php mu, di akhirnya tambahin</div><pre>if(!$sql){
echo "Terjadi kesalahan : " . mysqli_error($koneksi);
}</pre><div><br>Lalu di ajax yang bersangkutan</div><pre>$(document).on('click', '#updateKodrek', <em>function</em>(event) {
event.preventDefault(); //<---------
$.ajax({
url: 'kodrek/simpanubah.php',
type: 'post',
data: $('#updateForm').serialize(),
success: <em>function</em>(data) { <---------
if(data.length > 0){
alert(data)
}else{
$('#modalubahKodrek').modal('hide');
location.reload();
}
}
});
});</pre><div><br>Fungsinya buat mengecek jika kodrek/simpanubah.php ada yang di echo, maka di manggil apa isi nya melalui alert(data)</div>
Tanggapan
masih sama kak.saya masukin kodingnya jg gak ada alert yg mncul
<div><br>script tmbol<br><br></div><pre> $(document).on('click', '#updateKodrek', <em>function</em>() { event.preventDefault(); $.ajax({ url: 'kodrek/simpanubah.php', type: 'post', data: $('#updateForm').serialize(), success: <em>function</em>(<em>data</em>) { $('#modalubahKodrek').modal('hide'); location.reload(); } });
});</pre><div><br>script simpanubah.php<br><br></div><pre> &lt;?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); }</pre><div><br>ss debug<br><br><figure data-trix-attachment="{"contentType":"image/png","filename":"image.png","filesize":99515,"height":899,"url":"https://i.ibb.co/FBTBS7H/image.png","width":1731}" data-trix-content-type="image/png" data-trix-attributes="{"presentation":"gallery"}" class="attachment attachment--preview attachment--png"><img src="https://i.ibb.co/FBTBS7H/image.png" width="1731" height="899"><figcaption class="attachment__caption"><span class="attachment__name">image.png</span></figcaption></figure><br><br><br><br></div>
Tanggapan
Kamu ga ada parameter event di dalam ('click', '#updateKodrek', function(event)
jadinya terjadi error dan terhenti sebelum menjalakankan ajax.
Atau hapus aja baris event.PreventDefault, soalnya ga ada hubungan nya ternyata ama kendalanya
<div>Kalau sudah di hapus event.preventDefault nya.</div><pre>$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");
echo "test"; //<-------
if(!$sql){ echo "Terjadi Kesalahan : " . mysqli_error($koneksi); }</pre><div><br>Bukan cara yang cantik, cuman memastikan aja jika yang diubah beneran file yang dimaksud dan bisa ditangkep melalui ajax.</div>
Tanggapan
masih sama kak,saya masukin line echonya,saat klik simpan,gak muncul tulisan testnya.maaf ya kak saya banyak nanya.
<div>ini hasil scriptnya<br><br></div><pre>$sql = mysqli_query($koneksi, "UPDATE kodrek SET kd6='".$kd6."' WHERE idkd6='".$idkd6."'");
echo "test";
if(!$sql){ echo "Terjadi Kesalahan : " . mysqli_error($koneksi); }</pre><div><br></div>
Tanggapan
ya gak bisa ngeliat alert nya soalnya ajax mu kan belum diubah. gak ada pengecekan data.length > 0