我目前正在尝试更新MySQL数据库中的现有记录,这是我的表单:
<?php
$tampilann = mysql_query("SELECT * FROM `gajikaryawanluar` WHERE no_karyawan ='$_GET[id]' AND id_gajikaryawan='$_GET[gk]'");
$x12 = mysql_fetch_array($tampilann);
echo " <div class='box-header well' data-original-title>
<h2><i class='icon-user'></i> EDIT Gaji Karyawan -'$t[nama]'-</h2>
<div class='box-icon'>
<a href='#' class='btn btn-setting btn-round'><i class='icon-cog'></i></a>
<a href='#' class='btn btn-minimize btn-round'><i class='icon-chevron-up'></i></a>
<a href='#' class='btn btn-close btn-round'><i class='icon-remove'></i></a>
</div>
</div>
<div class='box-content'>
<form name='form_demand' class='form-horizontal' method=POST action='modul/mod_gaji/aksi_gajikaryawan.php?module=gajikaryawan&act=edit_gajikaryawanluarlama'' enctype='multipart/form-data'>
<div class='control-group'>
<label class='control-label' for='typeahead'>Id Gaji Karyawan </label>
<div class='controls'>
<input type='hidden' name='id_gajikaryawanluarlama' value='$_GET[gk]' >
<input type='hidden' name='id_gajikaryawan' value='$x12[id_gajikaryawan]' >
<input type='text' name='id_gajikaryawan' value='$x12[id_gajikaryawan]'disabled >
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Id Karyawan</label>
<div class='controls'>
<input type='text' class='span3 typeahead' id='typeahead' name='no_karyawan' value='$t[no_karyawan]' >
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Nama Karyawan</label>
<div class='controls'>
<input type='text' name='nama' value='$t[nama]' disabled >
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Bagian Kerja</label>
<div class='controls'>
<input type='text' name='bagiankerja' value='$t[bagian]' disabled>
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Tahun</label>
<div class='controls'>
<input type='text' class='span3 typeahead' id='typeahead' name='tahun' value='$tahun' >
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Tahun</label>
<div class='controls'>
<input type='text' class='span3 typeahead' id='typeahead' name='bln' value='".bulan($x12[bulan])."' >
<input type='hidden' name='bulan' value='$x12[bulan]' >
</div>
</div>
<br><br><table class='table table-striped table-bordered bootstrap-datatable datatable'><thead>
<tr><th width='30px'><p align='center'>NO</p></th><th width='20px'><p align='center'>Nilai</p></th><th width='50px'><p align='center'>Harga Barang</p></th><th width='20px'><p align='center'>Jumlah Barang</p></th></tr></thead>";
$tampil_barangdalam= mysql_query("SELECT * FROM barangluar order by id_barangluar asc ");
$no = 1;
while ( $r = mysql_fetch_array($tampil_barangdalam) )
{
$hargabaruf = number_format( $r[hargabaru], 0, ",", "." );
$hargalamaf = number_format( $r[hargalama], 0, ",", "." );
echo "<tr><td><p align='center'>$no</p></td>
<td><p align='center'>$r[nilai] </p></td>
<td><p align='center'><input type='hidden' class='span5 typeahead' name='id_barangluar[]' value ='$r[id_barangluar]'>
<input type='hidden' class='span5 typeahead' name='hargabaru[]' value ='$r[hargalama]'> Rp $hargalamaf</p></td>
<td><p align='center'><input type='text' class='span5 typeahead' name='jumlahbarang[]' value ='$r[hasil]' > </p></td>
";
$no++;
}
echo "</table>
<div class='control-group'>
<label class='control-label' for='typeahead'>DML</label>
<div class='controls'>
<input type='text' name='dml' value ='$x12[dml]'>
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Potongan</label>
<div class='controls'>
<input type='text' name='potongan' value ='$x12[potongan]'>
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Nilai Potongan</label>
<div class='controls'>
<input type='text' name='nilaipotongan' value ='$x12[nilaipotongan]' >
</div>
</div>
<div class='control-group'>
<label class='control-label' for='typeahead'>Bonus Target</label>
<div class='controls'>
<input type='text' name='bonustarget' value ='$x12[bonustarget]' >
</div>
</div>
<div class='form-actions'>
<button type='submit' class='btn btn-primary'>Save changes</button>
<button type='reset' class='btn'>Cancel</button>
</div>
</fieldset>
</form>
</div>
";
这是更新脚本。
<?php
$id_gajikaryawanluarlama = $_POST['id_gajikaryawanluarlama'];
$id_gajikaryawan = $_POST['id_gajikaryawan'];
$no_karyawan = $_POST['no_karyawan'];
$tahun = $_POST['tahun'];
$bulan = $_POST['bulan'];
$jumlahbarang = $_POST['jumlahbarang'];
$dml = $_POST['dml'];
$potongan = $_POST['potongan'];
$nilaipotongan = $_POST['nilaipotongan'];
$bonustarget = $_POST['bonustarget'];
$id_barangluar = $_POST['id_barangluar'];
foreach ($id_barangluar as $key => $idbarangluar) {
$jumlahbarang = $_POST['jumlahbarang'][$key];
$hargabarang = $_POST['hargabaru'][$key];
$hasiltotal= ($jumlahbarang * $hargabarang);
$hasil = mysql_query(" UPDATE `lympersada`.`gajikaryawanluar` SET `id_gajikaryawan` ='$id_gajikaryawan',
`no_karyawan`='$no_karyawan',
`id_barangluar`='$idbarangluar',
`tahun`='$tahun',
`bulan`='$bulan',
`hasil`='$jumlahbarang',
`dml`='$dml',
`potongan`='$potongan',
`nilaipotongan`='$nilaipotongan',
`bonustarget`='$bonustarget' where `id_gajikaryawan`='$id_gajikaryawanluarlama' ;"
);
$hasil2 = mysql_query(" UPDATE `lympersada`.`reportgaji` SET `id_gajikaryawan`='$id_gajikaryawan',
`no_karyawan`='$no_karyawan',
`tahun`='$tahun',
`bulan`='$bulan',
`hasiltotal`='$hasiltotal' where `id_gajikaryawan`='$id_gajikaryawanluarlama'; "
);
当我尝试更新数组时,数据只输入数据库中来自输入的最新数据。代码错在哪里?任何人都能帮忙,如何解决?