I have 3 file :
1. index.php
2. form.php
3. validasi form
i have a problem if I include file form.php into index.php,
why if I included form.php into index.php all field that I fill is inserted to database, but why only field picture is not inserted to database.
but if I not use index.php, just call form.php in browser all field are inserted also field picture...
I need your help please...
this is my code :
Quoted Text Here
index.php
<!DOCTYPE html>
<html>
<head>
<title>Informasi Peralatan</title>
<div id="container">
<div id="text">
<h1>Data informasi aset <br> Gedung BOP</h1>
<h2>PT.PLN (PERSERO) SEKTOR PEMBANGKITAN TARAHAN</h2>
</div>
<div id="center">
<link rel="stylesheet" href="../CSS/alat.css" type="text/css" media="screen" />
<link href="../jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
<script src="../jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js"></script>
<script src="../jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script>
<script>
$(document).ready(function() {
$("#tabs").tabs();
});
</script>
</head>
<body style="font-size:62.5%;">
<div id="tabs">
<ul>
<li><a href="#fragment-1"><span>Tambah Data Peralatan</span></a></li>
</ul>
<div id="fragment-1">
<p></p>
<pre><code></code></pre>
/* <?php include "form_bop.php"; ?> */
</div>
<style type="text/css">
#slider { margin: 10px; }
</style>
<script>
$(document).ready(function() {
$("#slider").slider();
});
</script>
</head>
<body style="font-size:62.5%;">
<div id="slider"></div>
<div id="footer">
<script>
$(function(){
$( "button,input:submit,a".".demo").button();
$("a",".demo").click(function() {return false;});
});
</script>
<div class="demo">
<input type="submit" value="Tambah">
<a href="#">tambah.php</a>
<input type="submit" value="Edit">
<a href="#"></a>
<input type="submit" value="Hapus">
<a href="#"></a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Quoted Text Here
and this file form.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php include "koneksi.php" ?>
<head>
<title>Input data peralatan</title>
<link href="../jquery-ui-1.8.16.custom/development-bundle/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
<script src="../jquery-ui-1.8.16.custom/js/jquery-1.6.2.min.js"></script>
<script type="text/javascript"> var jY = $.noConflict(true); </script>
<script src="../jquery-ui-1.8.16.custom/js/jquery-ui-1.8.16.custom.min.js"></script>
<!--script jqery form!-->
<script src="jquery-1.2.3.min.js"></script>
<script type="text/javascript"> var jQ = $.noConflict(true); </script>
<script type="text/javascript">
jQ(document).ready(function() {
jQ().ajaxStart(function() {
jQ('#loading').show();
jQ('#result').hide();
}).ajaxStop(function() {
jQ('#loading').hide();
jQ('#result').fadeIn('slow');
});
jQ('#frm').submit(function() {
jQ.ajax({
type: 'POST',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data) {
jQ('#result').html(data);
}
})
return false;
});
})
</script>
<!--Akhir dari jquery form!-->
<!---datepicker!-->
<script>
$(document).ready(function() {
$( "#tanggal" ).datepicker({ altFormat: 'yy-mm-dd' });
$( "#tanggal" ).change(function() {
$( "#tanggal" ).datepicker( "option", "dateFormat","yy-mm-dd" );
});
});
</script>
<body style="font-size:60.5%;">
<div id="datepicker"></div>
<!--akhir dari datepicker!-->
<!--CSS Form dan Validasi form !-->
<style type="text/css">
body, table, input, select, textarea { font: 11px/20px Verdana, sans-serif; }
h4 { font-size: 18px; }
input { padding: 3px; border: 1px solid #999; }
td { padding: 3px; }
#result { background-color: #F0FFED; border: 1px solid #215800; padding: 10px; width: 400px; margin-bottom: 20px; }
</style>
<style type="text/css">
.error {
font-size:small;
color:red;
}
</style>
<!--akhir CSS Form dan Validasi form !-->
<!-- awal ajax ->
<script type="text/javascript">
$(document).ready(function() {
//aktifkan ajax di form
var options = {
success : showResponse,
resetForm : true,
clearForm : true,
dataType : 'json'
};
$('#frm').ajaxForm(options);
});
function showResponse(responseText, statusText) {
var data = responseText['data'];
var pesan = responseText['pesan'];
alert(pesan);
}
</script>
<!-- akhir!-->
<h4>Input Data Peralatan</h4>
<div id="loading" style="display:none;"><img src="loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<form action="input.php" enctype="multipart/form-data" method="post" id="frm">
<table>
<tr>
<td><label for="nama" class="labelfrm">Nama Alat</label></td>
<td>
<input name="nama" id="nama"size="40" type="text" class="required"/>
</td>
</tr>
<tr>
<td><label for="part_no" class="labelfrm">Part No</label></td>
<td>
<input name="part_no" id="part_no" size="40" type="text" />
</td>
</tr>
<tr>
<td><label for="jenis" class="labelfrm">Jenis</label></td>
<td>
<select name="jenis">
<?php
$tampil=("SELECT * FROM jenis_aset");
$query_hasil=mysql_query($tampil);
while($r=mysql_fetch_object($query_hasil))
{
echo "<option value=$r->Id_jenis>$r->Jenis</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><label for="lokasi" class="labelfrm">Lokasi</label></td>
<td>
<input name="lokasi" id="lokasi" size="60" type="text" />
</td>
</tr>
<tr>
<td><label for="label" class="labelfrm">Merek<label></td>
<td>
<input name="merek" id="merek" size="30" type="text" />
</td>
</tr>
<tr>
<td><label for="satuan" class="labelfrm">Satuan</label></td>
<td>
<input name="satuan" id="satuan" size="30" type="text" />
</td>
</tr>
<tr>
<td><label for="jumlah" class="labelfrm">Jumlah</td>
<td>
<input name="jumlah" id="jumlah" size="30" type="text" />
</td>
</tr>
<tr>
<td><label for="tanggal" class="labelfrm">Expired</label></td>
<td>
<input name="tanggal" id="tanggal" type="text" />
</td>
</tr>
<tr>
<td><label for="fungsi" class="labelfrm">Fungsi</label></td>
<td>
<textarea name="fungsi" id="fungsi" cols="40" rows="3">
Quoted Text Here
this file validasi_form.php
<?php
include ("koneksi.php");
/* penanganan form */
if (trim($_POST['nama']) == '') {
$error[] = '- Nama alat masih kosong';
}
if (trim($_POST['fungsi']) == '') {
$error[] = '- Fungsi harus diisi';
}
if (trim($_POST['keterangan']) == '') {
$error[] = '- Keterangan harus diisi';
}
if (isset($error)) {
echo '<b>Error</b>: <br />'.implode('<br />', $error);
}
else {
$Jenis = strip_tags($_POST['jenis']);
$Nama_peralatan = strip_tags($_POST['nama']);
$Part_no = strip_tags($_POST['part_no']);
$Lokasi = strip_tags($_POST['lokasi']);
$Merk = strip_tags($_POST['merek']);
$Satuan = strip_tags($_POST['satuan']);
$Jumlah = strip_tags($_POST['jumlah']);
$Expired = strip_tags($_POST['tanggal']);
$Fungsi = strip_tags($_POST['fungsi']);
$Keterangan = strip_tags($_POST['keterangan']);
$nama_file = strip_tags($_POST['gambar']);
//input ke db
//menentukan letak direktori file
$lokasi_file = $_FILES['gambar']['tmp_name'];
$nama_file = $_FILES['gambar']['name'];
$direktori ="images/$nama_file";
// Apabila tidak ada gambar yang di upload
if (empty($lokasi_file)){
$query = sprintf("INSERT INTO lab_batubara (id,
jenis,
Nama_peralatan,
Part_No,
Lokasi,
Merk,
Satuan,
Jumlah,
Expired,
Fungsi,
Keterangan,
Gambar)
VALUES ('',
'$Jenis',
'$Nama_peralatan',
'$Part_no',
'$Lokasi',
'$Merk',
'$Satuan',
'$Jumlah',
'$Expired',
'$Fungsi',
'$Keterangan',
'$nama_file')",
mysql_escape_string($Nama_peralatan),
mysql_escape_string($Part_no),
mysql_escape_string($Lokasi),
mysql_escape_string($Merk),
mysql_escape_string($Satuan),
mysql_escape_string($Jumlah),
mysql_escape_string($Expired),
mysql_escape_string($Fungsi),
mysql_escape_string($Keterangan)
);
}
// Apabila ada gambar yang diupload
else {
$move= move_uploaded_file($lokasi_file,"$direktori");
$query = sprintf("INSERT INTO lab_batubara (id,
jenis,
Nama_peralatan,
Part_No,
Lokasi,
Merk,
Satuan,
Jumlah,
Expired,
Fungsi,
Keterangan,
Gambar)
VALUES ('',
'$Jenis',
'$Nama_peralatan',
'$Part_no',
'$Lokasi',
'$Merk',
'$Satuan',
'$Jumlah',
'$Expired',
'$Fungsi',
'$Keterangan',
'$nama_file')",
mysql_escape_string($Nama_peralatan),
mysql_escape_string($Part_no),
mysql_escape_string($Lokasi),
mysql_escape_string($Merk),
mysql_escape_string($Satuan),
mysql_escape_string($Jumlah),
mysql_escape_string($Expired),
mysql_escape_string($Fungsi),
mysql_escape_string($Keterangan)
);
if ($move) {
echo("Done! File saved...");
}
else{
echo"gagal";
}
}
$sql = mysql_query($query);
if ($sql) {
$data = '';
foreach ($_POST as $k => $v) {
$data .= "$k : $v<br />";
echo "$data";
}
echo '<b>Form berhasil disubmit. Berikut ini data anda:</b><br />';
echo $data;} else {
$pesan = "Data gagal disimpan ";
$pesan.= mysql_error();
}
exit;
}
?>