- Beranda
- Komunitas
- Tech
- Website, Webmaster, Webdeveloper
master php masul, need help.
TS
hasand
master php masul, need help.
gini gan, ane punya problem jadi ane bkin list penjualan produk dengan chexbox sebagai tanda untuk memlilih produknya,
permasalahannya adalah ketika ane pilih cheksbox yg kedua, daftar harga + dll ga masuk ke database.
tapi klo ane cheksbox dari yg pertama sampe yg akhir itu datanya masuk smua gan.
ini codingannya gan :
<form method="post" action="step1" class="validate" enctype="multipart/form-data">
<input type="hidden" name="id_nasabah1" class="text" value="<?php echo $q3;?>" />
<?php
$query1 = mysql_query("select max(no_transaksi) as nomer from transaksi_pembelian ");
$q1 = mysql_fetch_array($query1);
$q2 = $q1 ['nomer'];
$q3 = (int) substr($q2,9,3);
$q3++;
$kode = "P";
$tanggal = date("dmY");
$new_code = $kode.$tanggal. sprintf("s",$q3);
?>
<input type="hidden" value="<?php echo $new_code;?>" name="no_transaksi" />
<?php
$query2 = mysql_query("select max(id_detail_pembelian) as nomer from det_transaksi_pembelian ");
$q12 = mysql_fetch_array($query2);
$q22 = $q12 ['nomer'];
$q33 = (int) substr($q22,9,3);
$q33++;
$kode2 = "DP";
$tanggal2 = date("dmY");
$new_code2 = $kode2.$tanggal2. sprintf("s",$q33);
?>
<input type="hidden" value="<?php echo $new_code2;?>" name="id_det_trans" />
<?php
$subq = mysql_query ("select * from produk order by id_produk");
while ($b = mysql_fetch_array($subq)) {
?>
<tr>
<td class="wwe-1rank"><input type="checkbox" name="asal[]" value="<?php echo $b['id_produk'];?>" style="margin-left:20px;" /></td>
<td class="wwe-align-left"><?php echo $b['nama'];?></td><td><?php echo $b['jenis'];?></td><td>IDR</td>
<td><input type="text" name="jumlah_beli[]" value="" /></td>
<td><?php echo $b['harga'];?></td>
<td><?php echo $b['prospektus'];?></td>
<input type="hidden" value="<?php echo $b['harga'];?>" name="harga_produk[]" />
<input type="hidden" value="<?php echo $new_code;?>" name="id2" />
</tr>
<?php } ?>
</tbody>
</table>
<div class="actions">
<div class="actions-left">
<input type="reset">
</div>
<div class="actions-right">
<input type="submit" name="submit" value="Selanjutnya">
</div>
</div>
</form>
dan ini step1.php nya gan :
<?php
$pilih = isset($_POST['asal']) ? $_POST['asal'] : null;
$jumlah_beli = isset($_POST['jumlah_beli']) ? $_POST['jumlah_beli'] : null;
$no_transaksi = isset($_POST['no_transaksi']) ? $_POST['no_transaksi'] : null;
$id_nasabah = isset($_POST['id_nasabah1']) ? $_POST['id_nasabah1'] : null;
$harga_produk = isset($_POST['harga_produk']) ? $_POST['harga_produk'] : null;
$id_det = isset($_POST['id_det_trans']) ? $_POST['id_det_trans'] : null;
$id2 = isset($_GET['id_det_trans']) ? $_GET['id_det_trans'] : null;
$status = "Belum Dibayar";
$total_harga = 0;
foreach($pilih as $key=>$value){
$qty[$key] = $jumlah_beli[$key] / $harga_produk[$key];
$sql=mysql_query("insert into det_transaksi_pembelian values ('','$no_transaksi','".$value."','".$qty[$key]."','".$harga_produk[$key]."','".$jumlah_beli[$key]."'");
$total_harga += $jumlah_beli[$key];
$stok[$key] = $jumlah_beli[$key];
$sql2= mysql_query("insert into asset values ('','$id_nasabah','".$value."','".$qty[$key]."',CURDATE())");
if (!$sql && !$sql2)
echo mysql_error();
}
$sql0 = mysql_query ("insert into transaksi_pembelian values ('$no_transaksi',CURDATE(),CURTIME(),'$id_nasabah',$total_harga,'$status'");
if ($sql0) {
header("location:transaksi_pembelian_2");
}
else
{
echo "gagal";
}
?>
salah nya dmn ya gan ???help me gan
permasalahannya adalah ketika ane pilih cheksbox yg kedua, daftar harga + dll ga masuk ke database.
tapi klo ane cheksbox dari yg pertama sampe yg akhir itu datanya masuk smua gan.
ini codingannya gan :
<form method="post" action="step1" class="validate" enctype="multipart/form-data">
<input type="hidden" name="id_nasabah1" class="text" value="<?php echo $q3;?>" />
<?php
$query1 = mysql_query("select max(no_transaksi) as nomer from transaksi_pembelian ");
$q1 = mysql_fetch_array($query1);
$q2 = $q1 ['nomer'];
$q3 = (int) substr($q2,9,3);
$q3++;
$kode = "P";
$tanggal = date("dmY");
$new_code = $kode.$tanggal. sprintf("s",$q3);
?>
<input type="hidden" value="<?php echo $new_code;?>" name="no_transaksi" />
<?php
$query2 = mysql_query("select max(id_detail_pembelian) as nomer from det_transaksi_pembelian ");
$q12 = mysql_fetch_array($query2);
$q22 = $q12 ['nomer'];
$q33 = (int) substr($q22,9,3);
$q33++;
$kode2 = "DP";
$tanggal2 = date("dmY");
$new_code2 = $kode2.$tanggal2. sprintf("s",$q33);
?>
<input type="hidden" value="<?php echo $new_code2;?>" name="id_det_trans" />
<?php
$subq = mysql_query ("select * from produk order by id_produk");
while ($b = mysql_fetch_array($subq)) {
?>
<tr>
<td class="wwe-1rank"><input type="checkbox" name="asal[]" value="<?php echo $b['id_produk'];?>" style="margin-left:20px;" /></td>
<td class="wwe-align-left"><?php echo $b['nama'];?></td><td><?php echo $b['jenis'];?></td><td>IDR</td>
<td><input type="text" name="jumlah_beli[]" value="" /></td>
<td><?php echo $b['harga'];?></td>
<td><?php echo $b['prospektus'];?></td>
<input type="hidden" value="<?php echo $b['harga'];?>" name="harga_produk[]" />
<input type="hidden" value="<?php echo $new_code;?>" name="id2" />
</tr>
<?php } ?>
</tbody>
</table>
<div class="actions">
<div class="actions-left">
<input type="reset">
</div>
<div class="actions-right">
<input type="submit" name="submit" value="Selanjutnya">
</div>
</div>
</form>
dan ini step1.php nya gan :
<?php
$pilih = isset($_POST['asal']) ? $_POST['asal'] : null;
$jumlah_beli = isset($_POST['jumlah_beli']) ? $_POST['jumlah_beli'] : null;
$no_transaksi = isset($_POST['no_transaksi']) ? $_POST['no_transaksi'] : null;
$id_nasabah = isset($_POST['id_nasabah1']) ? $_POST['id_nasabah1'] : null;
$harga_produk = isset($_POST['harga_produk']) ? $_POST['harga_produk'] : null;
$id_det = isset($_POST['id_det_trans']) ? $_POST['id_det_trans'] : null;
$id2 = isset($_GET['id_det_trans']) ? $_GET['id_det_trans'] : null;
$status = "Belum Dibayar";
$total_harga = 0;
foreach($pilih as $key=>$value){
$qty[$key] = $jumlah_beli[$key] / $harga_produk[$key];
$sql=mysql_query("insert into det_transaksi_pembelian values ('','$no_transaksi','".$value."','".$qty[$key]."','".$harga_produk[$key]."','".$jumlah_beli[$key]."'");
$total_harga += $jumlah_beli[$key];
$stok[$key] = $jumlah_beli[$key];
$sql2= mysql_query("insert into asset values ('','$id_nasabah','".$value."','".$qty[$key]."',CURDATE())");
if (!$sql && !$sql2)
echo mysql_error();
}
$sql0 = mysql_query ("insert into transaksi_pembelian values ('$no_transaksi',CURDATE(),CURTIME(),'$id_nasabah',$total_harga,'$status'");
if ($sql0) {
header("location:transaksi_pembelian_2");
}
else
{
echo "gagal";
}
?>
salah nya dmn ya gan ???help me gan
0
1.8K
8
Komentar yang asik ya
Urutan
Terbaru
Terlama
Komentar yang asik ya
Komunitas Pilihan