Maaf sebelumnya, aku baru belajar PHP tp aku bingung bagaimana caranya agar jika say klik Submit akan terjadi proses simpan ke database dan terjadi proses cetak dari hasil input_an form tersebut, thank atas bantuannya.
Ini contoh coding saya, maaf masih berantakan
<?php
include "../inc/koneksi.php";
if(isset($_POST['kirim']) && ($_POST['kirim']==='Simpan'))
{
$tanggal=$_POST['today'];
$kode = $_POST['kode'];
$nama=$_POST['nama'];
$jumlah=$_POST['jumlah'];
$nopol=$_POST['nopol'];
$hm=$_POST['hm'];
$teknisi=$_POST['teknisi'];
foreach ($kode as $key => $inputData)
{
if(empty($nopol) or empty($teknisi) or empty($jumlah[$key]))
{
$error = "<script language='javascript'>
alert('FORM --> gak komplit, Kang !!');
document.location='?page=../transaksi/partOut';
</script>";
}
if(($nopol!="") && ($teknisi!="") && ($jumlah[$key]!="") && ($inputData!=""))
{
$cek_jumlah = mysql_query("SELECT sumStock FROM stock WHERE codeStock = '$inputData'");
$result = mysql_fetch_array($cek_jumlah);
if($result < $jumlah[$key])
{
echo "<script language='javascript'>
alert('JUMLAH STOCK --> tidak cukup, Kang !!');
document.location='?page=../transaksi/partOut';
</script>";
}
else
{
$query = mysql_query("insert into partout values(null,'$tanggal','$inputData','$nama[$key]','$jumlah[$key]','$hm','$nopol','$teknisi')");
mysql_query("UPDATE stock SET sumStock = (sumStock - ".$jumlah[$key].") WHERE codeStock ='$inputData'");
if($query)
{
echo"<meta http-equiv='refresh' content='2; url=?page=../transaksi/partOut'>";
}
else
{
$error= "<script language='javascript'>
alert('DATA --> gak masuk, Kang !!');
document.location='?page=../transaksi/partOut';
</script>";
}
}
}
}
if(isset($error))
{
echo"$error";
}
}
?>
<script type="text/javascript">
function deleteRow(tableID)
{
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++)
{
var row = table.rows[i];
var chkbox = row.cells[3].childNodes[0];
if(null != chkbox && true == chkbox.checked)
{
if(rowCount <= 2)
{
alert("Tidak bisa dihapus semua Kang !!");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}
catch(e)
{
alert(e);
}
}
</script>
<div class="post">
<h2 class="title"><a href="#">SPAREPART KELUAR</a></h2>
<p class="meta"><em><?php echo date("l, F j, Y, g:i a");?> Posted by <a href="#">Someone</a></em></p>
<div class="entry">
<p>
<form action="" method="post" name="partOut" class="form">
<table>
<tr>
<td width="100">Tanggal</td>
<td>:</td>
<td><input name="today" type="text" class="today" onkeypress="return handleEnter(this, event)">
<a href="javascript:void(0)" onClick="if(self.gfPop)gfPop.fPopCalendar(document.partOut.today);return false;" ><img src="../calender/calender.jpeg" alt="" name="popcal" width="34" height="29" border="0" align="absmiddle" id="popcal" /></a>
<td> </td>
<td> </td>
<td>HM</td>
<td>:</td>
<td>
<?php
$result = mysql_query("select * from armada order by hmBis asc");
$bisArray = "var hm = new Array();\n";
echo '<select name="hm" onchange="changeHm(this.value)">';
echo '<option>---</option>';
while ($row = mysql_fetch_array($result))
{
echo '<option value="' . $row['hmBis'] . '">' . $row['hmBis'] . '
</option>';
$bisArray .= "hm['" . $row['hmBis'] . "'] = {name:'" . addslashes(
$row['nopolBis'])."'};\n";
}
echo '</select>';
echo '<script type="text/javascript">';
echo $bisArray;
echo 'function changeHm(id)';
echo '{';
echo 'document.getElementById("nopol").value = hm[id].name;';
echo '}';
echo '</script>';
?>
</td>
</tr>
<tr>
<td>Teknisi</td>
<td>:</td>
<td><input name="teknisi" type="text" id="teknisi" onkeypress="return handleEnter(this, event)"></td>
<td> </td>
<td> </td>
<td>No-Pol Bis</td>
<td>:</td>
<td>
<?php
$result = mysql_query("select * from armada order by hmBis asc");
echo '<select name="nopol" id="nopol">';
echo '<option>---</option>';
while ($row = mysql_fetch_array($result))
{
echo '<option value="' . $row['nopolBis'] . '">' . $row['nopolBis'] . '
</option>';
}
echo '</select>';
?>
</td>
</tr>
<tr> </tr>
<tr> </tr>
</table>
<table id="datatable" class="datatable">
<tr>
<th>Kode</th>
<th>Nama Barang</th>
<th>Jumlah</th>
<th></th>
</tr>
<tr>
<td>
<?php
$result = mysql_query("select * from stock");
$stockArray = "var prdName = new Array();\n";
echo '<select name="kode[]" onchange="changeStock(this.value)">';
echo '<option>---</option>';
while ($row = mysql_fetch_array($result))
{
echo '<option value="' . $row['codeStock'] . '">' . $row['codeStock'] . '
</option>';
$stockArray .= "prdName['" . $row['codeStock'] . "'] = {name:'" . addslashes(
$row['nameStock'])."'};\n";
}
echo '</select>';
?>
</td>
<td><input type="text" name="nama[]" id="nama[]" onkeypress="return handleEnter(this, event)" class="nama"></td>
<td><input type="text" name="jumlah[]" onkeypress="return handleEnter(this, event)" class="jumlah"/></td>
<td><input type="checkbox" name="chk[]" onkeypress="return handleEnter(this, event)" onclick="deleteRow('datatable')"/></td>
</tr>
</table>
<table width="490">
<tr>
<td align="right"><input type="button" onclick="javascript:addRow('datatable')" value="Add"></td>
</tr>
<tr>
<td align="center">
<input type="submit" name="kirim" value="Simpan")>
<input type="reset" name="batal" value="Batal"></td>
</tr>
</table>
<script type="text/javascript">
<?php echo $stockArray;?>
function addActionToSelect()
{
$("#datatable select").unbind();
$("#datatable select").change(function()
{
var id = $(this).val();
$(this).parent().next().find('input').val(prdName[id].name);
});
}
$(function(){
addActionToSelect();
});
</script>
</form>
<iframe width=174 height=189 name="gToday:normal:../calender/normal.js" id="gToday:normal:../calender/normal.js" src="../calender/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>
</p>
</div>
<p class="metaview"><em><a href="javascript: void(0)" onClick="window.open('../transaksi/viewpartOut.php','mywindow','scrollbars=1, left=250,width=800,height=600')">Edit Data</a></em></p>
</div>