mas, saya bikin input data yang pakai validasi, pesan errornya jalan, tapi kenpa tidak bisa tersimpan ya datanya?
<?php
session_start();
if(isset($_SESSION['error'])){
$error=$_SESSION['error'];
$_POST=$_SESSION['post'];
unset($_SESSION['error']);
unset($_SESSION['post']);
}
include "../connect.php";
$hasil = mysql_query("SELECT max(id_low) as maxID FROM lowongan");
$data = mysql_fetch_array($hasil);
$idMax=$data['maxID'];
// mengambil angka atau bilangan dalam kode anggota terbesar,
// dengan cara mengambil substring mulai dari karakter ke-0 diambil 4 karakter
// misal '00001', akan diambil '0001'
// setelah substring bilangan diambil lantas dicasting menjadi integer
$noUrut = (int) substr($idMax, 0, 4);
// bilangan yang diambil ini ditambah 1 untuk menentukan nomor urut berikutnya
$noUrut++;
// membentuk kode anggota baru
// perintah sprintf("%04s", $noUrut); digunakan untuk memformat string sebanyak 4 karakter
// misal sprintf("%04s", 12); maka akan dihasilkan '0012'
// atau misal sprintf("%04s", 1); maka akan dihasilkan string '0001'
$newID = sprintf("%04s", $noUrut);
// kode anggota yang baru di atas nanti akan ditampilkan dalam komponen text box
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Situs Lowongan Kerja Universitas Kristen Duta Wacana</title>
<link href="../adminstyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="wrapper">
<div id="header-wrapper"><a href="../index.php"><img src="../images/silokerukdw.jpg"/></a>
<!--<div id="header">
<div id="logo">
</div>
</div>-->
</div>
</div>
<!-- end #header -->
<div id="navigation">
<ul>
<a href="hal_admin.php">ADMIN </a>
<a href="perusahaan.php">PERUSAHAAN</a>
<li id="current"><a href="lowongan.php">LOWONGAN</a></li>
<a href="kriteria.php">KRITERIA</a>
<a href="logout.php">LOGOUT</a>
</ul>
</div>
<!-- end #navigation -->
<div id="page">
<div id="content">
<p>
<?php
if(empty($_SESSION[user])and empty($_SESSION[pass])){
echo "<center>Untuk mengakses data, anda harus LOGIN dulu</center><br>";
echo "<center><a href=login.php><b>LOGIN</b></a></center>";
}
//kalau sudah login benar
else{
$nama_bulan=array(1=>"Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
echo "<h2>Tambah Data Lowongan :</h2>
<form method=post action=input_lowongan.php>
<table>
<tr>";
?>
<!-- NGISI SENDIRI KODE OTOMATIS INCREMENT -->
<td class=noborder>ID Low</td>
<td class=noborder>:</td>
<td class=noborder><input type="text" name="id_low" maxlength="4" value="<?php echo $newID; ?>" size=10 disabled/>
<input name="id" type="hidden" value="<?php echo $newID; ?>" /></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Posisi</td>
<td class=noborder>:</td>";
?>
<td class=noborder><input name="lowongan" type="text" size="50" maxlength="100" value="<?php echo isset($_POST['lowongan']) ? $_POST['lowongan'] : '';?>" /></td>
</tr>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['lowongan'])?$error['lowongan']:''; ?></div></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Perusahaan</td>
<td class=noborder>:</td>
<td class=noborder><select name=perusahaan>";
//nampilin combobox dari field nama perusahaan
$tampil=mysql_query("select * from perusahaan order by perusahaan");
echo "<option value=belum pilih selected=selected>-pilih-</option>";
while($r=mysql_fetch_array($tampil)){
echo"<option value=$r[id_per]>$r[perusahaan]</option>";
}
echo "</select></td>
</tr>";
?>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['perusahaan'])?$error['perusahaan']:''; ?></div></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Min. IPK</td>
<td class=noborder>:</td>";
?>
<td class=noborder><input name="min_ipk" type="text" size="4" maxlength="4" value="<?php echo isset($_POST['min_ipk']) ? $_POST['min_ipk'] : '';?>" /></td>
</tr>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['min_ipk'])?$error['min_ipk']:''; ?></div></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Min. Usia</td>
<td class=noborder>:</td>";
?>
<td class=noborder><input name="min_usia" type="text" size="2" maxlength="2" value="<?php echo isset($_POST['min_usia']) ? $_POST['min_usia'] : '';?>" /></td>
</tr>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['min_usia'])?$error['min_usia']:''; ?></div></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Max. Usia</td>
<td class=noborder>:</td>";
?>
<td class=noborder><input name="min_usia" type="text" size="2" maxlength="2" value="<?php echo isset($_POST['max_usia']) ? $_POST['max_usia'] : '';?>" /></td>
</tr>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['max_usia'])?$error['max_usia']:''; ?></div></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Penempatan</td>
<td class=noborder>:</td>
<td class=noborder><select name=penempatan>";
//nampilin combobox dari field nama perusahaan
$tampil=mysql_query("select * from penempatan order by id_tempat");
echo "<option value=belum pilih selected=selected>-pilih-</option>";
while($r=mysql_fetch_array($tampil)){
echo"<option value=$r[id_tempat]>$r[penempatan]</option>";
}
echo "</select></td></tr>";
?>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['penempatan'])?$error['penempatan']:''; ?></div></td>
</tr>
<?php
echo "<tr>
<td class=noborder>Jenjang</td>
<td class=noborder>:</td>
<td class=noborder><select name=jenjang>";
$tampil=mysql_query("select * from jenjang order by id_jenjang");
echo "<option value=belumpilih selected>-pilih-</option>";
while($r=mysql_fetch_array($tampil)){
echo"<option value=$r[id_jenjang]>$r[jenjang]</option>";
}
echo "</select></td></tr>";
?>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['jenjang'])?$error['jenjang']:''; ?></div></td>
</tr>
<?php
echo "
<tr>
<td class=noborder>Gender</td>
<td class=noborder>:</td>
<td class=noborder>
<select name=gender>
<option value=semua>Semua</option>
<option value=pria>Pria</option>
<option value=wanita>Wanita</option>
</select>
</td>
</tr>";
?>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['gender'])?$error['gender']:''; ?></div></td>
</tr>
<?php
echo "
<tr>
<td class=noborder>Tgl Expired</td>
<td class=noborder>:</td>
<td class=noborder>";
//TANGGAL
echo "<select name=tanggal>
<option value=0 selected>Tgl</option>";
for($tgl=1;$tgl<=31;$tgl++){
//hitung panjang karakter tanggal
$panjang_karakter=strlen($tgl);
//jika cuma 1 digit, tambah 0 di depannya
if($panjang_karakter==1)
$i="0".$tgl;
else
$i=$tgl;
echo "<option value=$i>$i</option>";
}
echo "</select>";
//BULAN
echo "<select name=bulan>
<option value=0 selected>Bulan</option>";
for($bln=1;$bln<=12;$bln++){
echo "<option value=$bln>$nama_bulan[$bln]</option>";
}
echo "</select>";
//TAHUN
$thn_skrg=date("Y");
echo "<select name=tahun>
<option value=0 selected>Tahun</option>";
for($thn=2011;$thn<=$thn_skrg;$thn++){
echo "<option value=$thn>$thn</option>";
}
echo "</select>";
echo "</td>
</tr>";
?>
<tr>
<td class="noborder" colspan="2"></td>
<td class="noborder"><div style="color:#F00"><?php echo isset($error['tanggal'])?$error['tanggal']:''; ?> - <?php echo isset($error['bulan'])?$error['bulan']:''; ?> - <?php echo isset($error['tahun'])?$error['tahun']:''; ?></div></td>
</tr>
<?php
echo "
<tr>
<td class=noborder>Keterangan</td>
<td class=noborder>:</td>
<td class=noborder><textarea name=keterangan cols=50 rows=4></textarea></td>
</tr>
<tr>
<td class=noborder>Jurusan</td>
<td class=noborder>:</td>
<td class=noborder>";
//nampilin checkbox dari tabel jurusan
$tampil=mysql_query("select * from jurusan order by id_jur");
$no=1;
while($jur=mysql_fetch_array($tampil)){
echo "<input type='checkbox' value='".$jur['id_jur']."' name='jurusan".$no."'>".$jur['jurusan']."<br>";
$no++;
}
?>
<input type=hidden name=jumjur value="<?php echo $no-1; ?>">
<td class=noborder><font size=-3 color="#FF0000">*)harus diisi</font></td>
<?php
echo "</td>
</tr>
<tr>
<td colspan=3 class=noborder><input type=submit name=submit value=Simpan>
<a href=lowongan.php><input type=button value=Batal></a></td>
</tr>
</table></form>";
}
?>
</p>
<p> </p>
</div>
</div>
<div id="footer">
© 2012 Situs Lowongan Kerja UKDW
</div>
</body>
</html>
<?php
session_start();
include "../connect.php";
if($_POST){
$id_low = $_POST['id'];
$lowongan = $_POST['lowongan'];
$id_per = $_POST['perusahaan'];
$min_ipk = $_POST['min_ipk'];
$min_usia = $_POST['min_usia'];
$max_usia = $_POST['max_usia'];
$id_tempat = $_POST['penempatan'];
$id_jenjang = $_POST['jenjang'];
$gender = $_POST['gender'];
$keterangan = $_POST['keterangan'];
$tanggal=$_POST['tanggal'];
$bulan=$_POST['bulan'];
$tahun=$_POST['tahun'];
$jumjur = $_POST['jumjur'];
$polaipk="^[0-4]{1}\.[0-9]{2}$";
$error=array();
if(empty($lowongan)){
$error['lowongan']="Posisi lowongan harus diisi";
}
if(empty($perusahaan)){
$error['perusahaan']="Perusahaan harus diisi";
}
if(empty($penempatan)){
$error['penempatan']="Penempatan harus diisi";
}
if(empty($jenjang)){
$error['jenjang']="Jenjang harus diisi";
}
if(empty($gender)){
$error['gender']="Gender harus diisi";
}
if(empty($tanggal)){
$error['tanggal']="Tanggal harus diisi";
}
if(empty($bulan)){
$error['bulan']="Bulan harus diisi";
}
if(empty($tahun)){
$error['tahun']="Tahun harus diisi";
}
if(!empty($min_ipk)){
if(!eregi($polaipk,$min_ipk)){
$error['min_ipk']="Nilai ipk salah. Contoh 3.00";
}
}
if(!empty($min_usia)){
if(!is_numeric($min_usia)){
$error['min_usia']="Nilai minimal usia harus berupa angka";
}
}
if(!empty($max_usia)){
if(!is_numeric($max_usia)){
$error['max_usia']="Nilai maksimal usia harus berupa angka";
}
}
if(empty($error)){
mysql_query("insert into lowongan(id_low,lowongan,id_per,min_ipk,min_usia,max_usia,id_tempat,id_jenjang,gender,expired,keterangan) values('$id_low','$lowongan','$id_per','$min_ipk','$min_usia','$max_usia','$id_tempat','$id_jenjang','$gender',('$tahun-$bulan-$tanggal'),'$keterangan')");
//UNTUK MENAMBAHKAN ID_JUR KE LOWJUR
for($i=1;$i<=$jumjur;$i++){
$jurusan=$_POST['jurusan'.$i];
if(!empty($jurusan)){
mysql_query("insert into low_jur(id_low,id_jur) values('$id_low','$jurusan')");
}
}
header('location:lowongan.php');
}
else{
$_SESSION['error']=$error;
$_SESSION['post']=$_POST;
header('location:tambah_lowongan.php');
}
}
?>
terimakasih