Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
data delivery_detail tidak berhasil terinput ke database
Begini bang, saya bikin form delivery & delivery detail di 1 halaman. untuk bagian delivery sudah berhasil masuk ke database, tapi dibagian delivery detail tidak berhasil masuk ke database. tolong beritahu saya salahnya dimana, saya baru belajar PHP procedural
sedangkan untuk struktur database di table delivery_detail seperti ini
id
iddev
idpro
box
qty
untuk file yang saya kerjakan sudah saya lampirkan
<?php
require "conn.php";
include "header.php";
include "nav.php";
include "no_surat_jalan_unik.php";
?>
<div class="container-fluid">
<form method="POST" action="proses_input_surat_jalan.php">
<div class="row">
<div class="col-lg-3">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Surat Jalan</h6>
</div>
<div class="card-body">
<div class="card-body">
<div class="form-group">
<label>Nomor Surat Jalan</label>
<input type="text" name="nodev" id="nodev" class="form-control" value="<?php echo $kodeauto ?>" readonly>
</div>
<div class="form-group">
<label>Customer</label>
<select name="idcust" id="idcust" class="form-control select2">
<option value="">Pilih Customer</option>
<?php
$sql = "SELECT * FROM customers";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row["idcust"].'">'.$row["nmcust"].'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label>Nomor PO</label>
<input type="text" name="nopo" id="nopo" class="form-control">
</div>
<div class="form-group">
<label>Tanggal Kirim</label>
<div class="input-group date" id="tglkirim_container" data-target-input="nearest">
<input type="date" name="tglkirim" id="tglkirim_input" class="form-control datetimepicker-input" data-target="#tgl_kirim_picker" required>
<div class="input-group-append" data-target="#tglkirim_container" data-toggle="datetimepicker">
<!-- <div class="input-group-text"></div> -->
</div>
</div>
<script>
var tgl_kirim_input = document.getElementById('tglkirim_input');
tgl_kirim_input.addEventListener('change', function() {
var tgl_kirim = tgl_kirim_input.value;
// lakukan sesuatu dengan nilai tgl_kirim di sini
});
</script>
</div>
<div class="form-group">
<label>Nomor Plat</label>
<input type="text" name="plat" id="plat" class="form-control">
</div>
<div class="form-group">
<label>Driver</label>
<input type="text" name="driver" id="driver" class="form-control">
</div>
<div class="form-group">
<label>Catatan</label>
<textarea name="catatdev" id="catatdev" class="form-control"> </textarea>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-9">
<div class="card shadow mb-4">
<div class="card-header py-3">
<button type="button" class="add-field btn btn-primary" data-toggle="tooltip" data-placement="top" title="Tambah Item"> <i class="fas fa-plus-circle"></i></button>
<button type="submit" class="btn btn-success ml-5" name="simpan" data-toggle="tooltip" data-placement="top" title="Simpan Surat Jalan"><i class="fas fa-save"></i></button>
</div>
<div class="card-body">
<div class="card-body" id="dynamic-fields-container">
<div class="form-row">
<div class="col-8 mt-1">
<label>ITEM</label>
<?php
$ambildata = mysqli_query($conn, "SELECT * FROM products");
echo '<select name="nmpro[]" class="form-control">';
echo '<option value="">Pilih Barang</option>';
while ($tampil = mysqli_fetch_array($ambildata)) {
echo '<option value="'.$tampil['nmpro'].'">'.$tampil['nmpro'].'</option>';
}
echo '</select>';
?>
</div>
<div class="col mt-1">
<label>BOX</label>
<input type="text" name="box[]" class="form-control">
</div>
<div class="col mt-1">
<label>QTY</label>
<input type="text" name="qty[]" class="form-control">
</div>
<div class="col mt-1">
<label>Hapus</label>
</div>
</div>
</div>
<div class="card-body">
<div class="form-row">
<div class="col-8 mt-1">
<label>.</label>
<input type="hidden" class="form-control">
</div>
<div class="col mt-1">
<label>Total Box</label>
<input type="text" name="ttlbox" id="total_box" class="form-control" readonly>
</div>
<div class="col mt-1">
<label>Total Qty</label>
<input type="text" name="ttlqtydev" id="total_qty" class="form-control" readonly>
</div>
<div class="col mt-1">
<label>.</label>
<input type="hidden" class="form-control">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<script>
// total box & qty
function countTotal() {
var totalBox = 0;
var totalQty = 0;
$('#dynamic-fields-container .form-row').each(function() {
var boxVal = parseFloat($(this).find('input[name="box[]"]').val());
var qtyVal = parseFloat($(this).find('input[name="qty[]"]').val());
if (!isNaN(boxVal)) {
totalBox += boxVal;
}
if (!isNaN(qtyVal)) {
totalQty += qtyVal;
}
});
$('#total_box').val(totalBox);
$('#total_qty').val(totalQty.toFixed(2)); // mengubah totalQty agar dapat menampilkan 2 angka dibelakang koma
}
$(document).ready(function(){
var i = 1;
$('.add-field').click(function(){
i++;
var newRow = '<div class="form-row">'+
'<div class="col-8 mt-1">'+
'<?php
$ambildata = mysqli_query($conn, "SELECT * FROM products");
echo '<select name="nmpro[]" class="form-control">';
echo '<option value="">Pilih Barang</option>';
while ($tampil = mysqli_fetch_array($ambildata)) {
echo '<option value="'.$tampil['nmpro'].'">'.$tampil['nmpro'].'</option>';
}
echo '</select>';
?>'+
'</div>'+
'<div class="col mt-1">'+
'<input type="text" name="box[]" class="form-control">'+
'</div>'+
'<div class="col mt-1">'+
'<input type="text" name="qty[]" class="form-control">'+
'</div>'+
'<div class="col mt-1">'+
'<button type="button" class="delete-row text-danger form-control"><i class="fas fa-fw fa-trash"></i></button>'+
'</div>'+
'</div>';
$('#dynamic-fields-container').append(newRow);
});
$(document).on('click', '.delete-row', function(){
$(this).closest('.form-row').remove();
i--;
countTotal(); // tambahkan pemanggilan countTotal() di sini
});
// Panggil fungsi untuk pertama kali
countTotal();
// Aktifkan fungsi saat input box atau input qty diubah
$('#dynamic-fields-container').on('input', 'input[name="box[]"], input[name="qty[]"]', function() {
countTotal();
});
});
// Mengubah judul halaman web
document.title = "Buat Surat Jalan";
</script>
<?php include "footer.php" ?>
//script proses input ke database
<?php
require "conn.php";
if(isset($_POST['simpan'])){
$nodev = mysqli_real_escape_string($conn, $_POST['nodev']);
$idcust = mysqli_real_escape_string($conn, $_POST['idcust']);
$nopo = mysqli_real_escape_string($conn, $_POST['nopo']);
$tglkirim = mysqli_real_escape_string($conn, $_POST['tglkirim']);
$plat = mysqli_real_escape_string($conn, $_POST['plat']);
$driver = mysqli_real_escape_string($conn, $_POST['driver']);
$catatdev = mysqli_real_escape_string($conn, $_POST['catatdev']);
$ttlbox = mysqli_real_escape_string($conn, $_POST['ttlbox']);
$ttlqtydev = mysqli_real_escape_string($conn, $_POST['ttlqtydev']);
if(isset($_POST['idpro'])) {
$idpro = array_map(function($value) use($conn) {
return mysqli_real_escape_string($conn, $value);
}, $_POST['idpro']);
} else {
$idpro = array();
}
if(isset($_POST['qty'])) {
$qty = array_map(function($value) use($conn) {
return mysqli_real_escape_string($conn, $value);
}, $_POST['qty']);
} else {
$qty = array();
}
if(isset($_POST['box'])) {
$box = array_map(function($value) use($conn) {
return mysqli_real_escape_string($conn, $value);
}, $_POST['box']);
} else {
$box = array();
}
// query untuk insert data ke tabel delivery
$sql = "INSERT INTO delivery (nodev, idcust, nopo, tglkirim, plat, driver, catatdev, ttlbox, ttlqtydev) VALUES ('$nodev', '$idcust', '$nopo', '$tglkirim', '$plat', '$driver', '$catatdev', '$ttlbox', '$ttlqtydev')";
$result = mysqli_query($conn, $sql);
if($result){
// ambil id delivery yang baru saja diinsert
$delivery_id = mysqli_insert_id($conn);
// loop untuk insert data ke tabel delivery_detail
foreach($idpro as $key => $value) {
$sql_detail = "INSERT INTO delivery_detail (iddev, idpro, qty, box) VALUES ('$delivery_id', '$value', '$qty[$key]', '$box[$key]')";
mysqli_query($conn, $sql_detail);
}
echo "<script>alert('Surat Jalan berhasil Disimpan.'); window.location='index.php';</script>";
} else {
echo "ERROR: Could not able to execute $sql. " . mysqli_error($conn);
}
}
?>
0
Tanggapan
coba tampilkan dulu errornya https://sekolahkoding.com/forum/cara-menampilkan-error-debug-di-php-1552899672
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban