Postingan lainnya
Cara insert Combobox dan Text
Tolong Bantuannya mas/mbak
saya kesusahan untuk koding ini. disini saya ingin menyimpan data ke database oracle. data combobox diambil dari tabel penyakit dan tabel gejala. ketika di simpan data yang tersimpan tersebut hanya kode penyakit dan kode gejala dan tersimpan ditabel relasi beserta nilai MB dan MD. tapi dari source code dibawah data tidak tersimpan.
tolong bantuannya.
=============================================================================================================
Form Tambah
<?php include "../templates/header_admin.php";?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Relasi</h1>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<form class="form-horizontal" method="post" action="../includes/proses_tambah_relasi">
<div class="form-group">
<label>Penyakit <span class="text-danger">*</span></label>
<select class="form-control" name="kode_penyakit" required>
<option >Nama Penyakit</option>
<?php
$sql = oci_parse($connect, "SELECT * FROM TBL_PENYAKIT ORDER BY KD_PENYAKIT");
oci_execute($sql);
while($datapenyakit = oci_fetch_array($sql)){
echo "<option>[$datapenyakit[KD_PENYAKIT]] $datapenyakit[NM_PENYAKIT]</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>Gejala <span class="text-danger">*</span></label>
<select class="form-control" name="kode_gejala" required>
<option >Nama Gejala</option>
<?php
$sql = oci_parse($connect, "SELECT * FROM TBL_GEJALA ORDER BY KD_GEJALA");
oci_execute($sql);
while($datapenyakit = oci_fetch_array($sql)){
echo "<option>[$datapenyakit[KD_GEJALA]] $datapenyakit[GEJALA]</option>";
}
?>
</select>
</div>
<div class="form-group">
<label>MB <span class="text-danger">*</span></label>
<input class="form-control" type="text" name="mb" value="" required />
</div>
<div class="form-group">
<label>MD <span class="text-danger">*</span></label>
<input class="form-control" type="text" name="md" value="" required />
</div>
<div class="form-group">
<button class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Simpan</button>
<a class="btn btn-danger" href="data_relasi?aksi=daftar"><span class="glyphicon glyphicon-arrow-left"></span> Kembali</a>
</div>
</form>
</div>
</div>
</div>
<script src="../assets/admin/vendor/jquery/jquery.min.js"></script>
<script src="../assets/admin/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/admin/vendor/metisMenu/metisMenu.min.js"></script>
<script src="../assets/admin/vendor/raphael/raphael.min.js"></script>
<script src="../assets/admin/vendor/morrisjs/morris.min.js"></script>
<script src="../assets/admin/data/morris-data.js"></script>
<script src="../assets/admin/dist/js/sb-admin-2.js"></script>
</body>
</html>
==============================================================================================================
Proses tambah
<?php
error_reporting(0);
include "../config.php";
function tambah ($connect, $KD_PENYAKIT, $KD_GEJALA, $MB, $MD){
$sql = "INSERT INTO TBL_RELASI VALUES ('$KD_PENYAKIT','$KD_GEJALA', '$MB', '$MD')";
$str = oci_parse($connect, $sql);
oci_execute($str);
$commit = oci_commit($connect);
if(!$commit){
echo "Proses Gagal";
exit();
}
}
?>
<?php
$sbm = $_POST['submit'];
if(isset($sbm)){
$kd_penyakit = $_POST['KD_PENYAKIT'];
$kd_gejala = $_POST['KD_GEJALA'];
$nilaimb = $_POST['MB'];
$nilaimd = $_POST['MD'];
tambah($connect, $kd_penyakit, $kd_gejala, $nilaimb, $nilaimd);
// header("location: ../admin/data_gejala");
}
?>
<script language="javascript">
alert("Berhasil Menambah Data Gejala");
document.location="../admin/data_relasi";
</script>
1 Jawaban:
Saya ga begitu tau dengan query ORACLE, cuma numpang kasih saran aja
Setau saya option itu, ada value dan ada text. Dan biasanya value ini yang akan di save
<option value='1'>LALALA</option>
Code anda
<option>1 LALALA</option>
echo "<option>[$datapenyakit[KD_GEJALA]] $datapenyakit[GEJALA]</option>";
Coba:
echo "<option value='".$datapenyakit['KD_GEJALA']."'>".$datapenyakit['GEJALA']."</option>";
Kalau hasil query kurang tau gan. Coba aja inspect, network saat anda save apa saja parameter2 POST nya