<form class="block-content form" name="form_account_edit" id="form_account_edit" method="post" enctype="multipart/form-data" action="http:haya.php" onsubmit="return IQ.checkForm(this,'checkPasswordAndPicture(document.form_account_edit);');">
<div class="columns">
<div class="colx2-left">
<table cellpadding="3" class="table-padding">
<tr title="Required">
<td><b>Produk</b><span class="required">*</span></td>
<td>:</td>
<td><select name="produk" id="cbproduk" style="width:212px"></select></td>
</tr>
<tr>
<td><b>Unit</b></td>
<td>:</td>
<td><select name="unit" id="cbunit_mk" style="width:212px"></select></td>
</tr>
</table>
</div>
</div>
<div class="block-footer" style="height:30px;">
<div class="float-right">
<button type="submit"><img src="images/icons/fugue/tick-octagon.png" width="16" height="16"> Save</button>
</div>
</div>
</form>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("combo");
$produk = htmlspecialchars($_POST['produk']);
$unit = htmlspecialchars($_POST['unit']);
$sql = "INSERT INTO air VALUES ('$produk','$unit')";
mysql_query($sql) or die ('Failed');
echo "<h1>Register Success</h1>";
echo "<br>";
?>
<script language="javascript">
function Load(data,primid){
$('#loading'+data).empty().append('<img src="img/ajax-loader.gif"/>');
$.post("option.php",{tipe:data,id:primid},
function(result){
$('#cb'+data).html(result);
$('#loading'+data).empty();
}
);
}
$(function(){
Load('produk',0);
$('#cbproduk').change(
function(){
if($('#cbproduk option:selected').val() !=''){
Load('unit_mk',$('#cbproduk option:selected').val());
}
}
);
});
</script>
<?php
mysql_connect ('localhost','root','');
mysql_select_db ('abms');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$tipedata = $_POST['tipe'];
$id = $_POST['id'];
switch($tipedata){
case 'unit_mk':
$sql='SELECT id,unit FROM '.$tipedata.' WHERE id_mk = "'.$id.'" ORDER BY unit ASC';break;
case 'produk':
$sql='SELECT id,kode,nama FROM '.$tipedata.' ORDER BY nama ASC';break;
}
$kueri=mysql_query($sql);
echo '<option value=""></option>';
while($row=mysql_fetch_object($kueri)){
echo '<option value="'.$row->id.'">';
switch($tipedata){
case 'unit_mk':
echo $row->unit;break;
case 'produk':
echo $row->nama;break;
}
echo '</option>';
}
}
?>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("combo");
$produk = htmlspecialchars($_POST['produk']);
$unit = htmlspecialchars($_POST['unit']);
$sql = "insert into air (produk,unit) select produk.nama, unit_mk.unit from produk INNER JOIN unit_mk ON produk.id = unit_mk.id_mk and $produk = produk.id";
mysql_query($sql) or die ('failed');
?>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("combo");
$produk = htmlspecialchars($_POST['produk']);
$unit = htmlspecialchars($_POST['unit']);
$lama = htmlspecialchars($_POST['lama']);
$sql = "insert into air (produk,unit) select produk.nama, unit_mk.unit from produk INNER JOIN unit_mk ON produk.id = unit_mk.id_mk and $produk = produk.id";
mysql_query($sql) or die ('failed');
?>