<?php
$hari_ini = date ("Y-m-d");
$tampil="SELECT * from tblpenghuni ORDER BY id_penghuni";
$hasil=mysql_query($tampil);
$data=mysql_fetch_array($hasil)
?>
<fieldset>
<form action = "aksi_penghuni.php?module=user&act=input" method="post" onsubmit='return ValidateForm(this)'>
<p><label for="no_ktp">Nomor KTP</label>
<input type="text" name="no_ktp" size="20" maxlength="18" onkeypress="return harusangka(event)"><br /></p>
<p><label for="nama_penghuni">Nama Penghuni</label>
<input type = "text" name = "nama_penghuni" size = "50" maxlength="50"><br /></p>
<p><label for="tempat_lahir">Tempat Lahir</label>
<input type="text" name = "tempat_lahir" size="50" maxlength="30"></input><br /></p>
<p><label for="tgl_lahir">Tanggal Lahir</label>
<select name="tanggal">
<?php
for ($tgl=1; $tgl<=31; $tgl++) {
echo "<option value='$tgl'> $tgl </option>";
}
?>
</select>-
<select name="bln">
<?php
$bulan=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
for($i=0;$i<=12;$i++){
echo("<option value='".$bulan[$i]."'>".$bulan[$i]."</option>");
}
?>
</select>
-<select name="tahun">
<?php
$thn_skrg=date("Y");
for ($thn=1970; $thn<=$thn_skrg; $thn++) {
echo "<option value=$thn> $thn </option>";
}
?>
</select> <br /></p>
<p><label for="kelamin">Kelamin</label>
<label><input name="kelamin" type="radio" value="Laki-laki" checked>Laki-laki</label>
<label><input type="radio" name="kelamin" value="Perempuan">Perempuan</label><br /></p>
<p><label for="agama">Agama</label>
<select name="agama" id="agama">
<option>Islam</option>
<option>Kristen Protestan</option>
<option>Kristen Khatolik</option>
<option>Budha</option>
<option>Hindu</option>
</select><br /></p>
<p><label for="id_penghuni">ID Penghuni</label>
<?php
$result = mysql_query("select * from perusahaan");
$jsArray = "var prdName = new Array();\n";
echo '<select name="prdId" onchange="document.getElementById(\'prd_name\').value = prdName[this.value]">';
echo '<option>pilih</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row . '">' . $row . '</option>';
$jsArray .= "prdName . "'] = '" . addslashes($row) . "';\n";
}
echo '</select>';
?>
<input type="text" name="prod_name" id="prd_name"/><br /></p>
<script type="text/javascript">
<?php echo $jsArray; ?>
</script>
<!--<option value="selected">Pilih Perusahaan</option>
<?php
$query= "select * from perusahaan";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
echo "<option value='".$data."'>".$data."</option>";
}
?>-->
<p><label for="deposit">Deposit</label>
<input type = "text" name = "deposit" size = "30" maxlength="20" onkeypress="return harusangka(event)"><br /></p>
<p><label for="status_kerja">Status Kerja</label>
<select name="status_kerja" id="status_kerja" >
<option>Permanen</option>
<option>Kontrak</option>
</select><br /></p>
<p><label for="status_aktif">Status</label>
<select name="status_aktif" id="status_aktif" >
<option>Aktif</option>
<option>Tidak aktif</option>
</select><br /></p>
<p><input type="submit" value="Simpan" class="formbutton"> <input type="reset" value="Batal" class="formbutton"></p>
</form>
untuk aksinya seperti ini script yang saya buat
<?php
include "security.php";
require_once("lib/koneksi.php");
DB_CON();
?>
<?php
$module= $_GET[module];
$act = $_GET[act];
//input perusahaan
if($module=='user' AND $act=='input')
{
$no_ktp=$_POST;
$nama_penghuni=$_POST;
$tempat_lahir=$_POST;
$tgl_lahir=$_POST.'-'.$_POST.'-'.$_POST;
$kelamin=$_POST;
$agama=$_POST;
$id_perusahaan=$_POST;
$deposit=$_POST;
$status_kerja=$_POST;
$status_aktif=$_POST;
$tgl_d=substr($tanggal,3,2);
$bln_d=substr($tanggal,0,2);
$thn_d=substr($tanggal,6,4);
$ttl="$tempat, $tgl_lahir";
$tgl_daftar="$thn_d-$bln_d-$tgl_d";
mysql_query("insert into tblpenghuni (no_ktp,nama_penghuni,tempat_lahir,tgl_lahir,kelamin,agama,id_perusahaan,deposit,status_kerja,status_aktif)values('$no_ktp','$nama_penghuni','$tempat_lahir','$tgl_lahir','$kelamin','$agama','$id_perusahaan','$deposit','$status_kerja','$status_aktif')");
echo "<script>alert('Selamat anda telah berhasil menyimpan data penghuni')</script>";
echo"<script>document.location.href=\"tampil_penghuni.php\";</script>";
//header('location: tampil_perusahaan.php');
}
//update perusahaan
if($module=='user' AND $act=='update')
{
$no_ktp=$_POST;
$nama_penghuni=$_POST;
$tempat_lahir=$_POST;
$tgl_lahir=$_POST;
$kelamin=$_POST;
$agama=$_POST;
$id_perusahaan=$_POST;
$deposit=$_POST;
$status_kerja=$_POST;
$status_aktif=$_POST;
$id=$_POST;
$tgl_d=substr($tanggal,3,2);
$bln_d=substr($tanggal,0,2);
$thn_d=substr($tanggal,6,4);
$ttl="$tempat, $tgl_lahir";
$tgl_daftar="$thn_d-$bln_d-$tgl_d";
mysql_query("update tblpenghuni set no_ktp='$no_ktp',nama_penghuni='$nama_penghuni',tempat_lahir='$tempat_lahir',tgl_lahir='$tgl_lahir',kelamin='$kelamin',agama='$agama',id_perusahaan='$id_perusahaan',depsoit='$deposit',status_kerja='$status_kerja',status='$status_aktif' where id_penguni='$id'");
echo "<script>alert('Selamat anda telah berhasil mengubah data penghuni')</script>";
echo"<script>document.location.href=\"tampil_perusahaan.php\";</script>";
//header('location: tampil_perusahaan.php');
}
//hapus user
if($module=='user' AND $act=='hapus')
{
$id=$_GET;
mysql_query("delete from tblpenghuni where id_penghuni='$id'");
echo "<script>alert('Selamat anda telah berhasil menghapus data penghuni')</script>";
echo"<script>document.location.href=\"tampil_penghuni.php\";</script>";
//header('location: tampil_perusahaan.php');
}
?>
Silahkan
login untuk menjawab!
salah kamu pada saat membuat combobox tanggal lahir dan combok perusahaan:
<!-- code seblumnya---->
<p><label for="tgl_lahir">Tanggal Lahir</label>
<select name="tanggal">
<?php
for ($tgl=1; $tgl<=31; $tgl++) {
echo '<option value="'.sprintf('%02s', $tgl).'">'.$tgl.'</option>';
}
?>
</select>-
<select name="bulan">
<?php
$bulan=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
for($i=0;$i<12;$i++){
echo '<option value="'.sprintf('%02s', $i+1).'">'.$bulan[$i].'</option>';
}
?>
</select>
-<select name="tahun">
<?php
$thn_skrg=date("Y");
for ($thn=1970; $thn<=$thn_skrg; $thn++) {
echo "<option value=$thn> $thn </option>";
}
?>
</select> <br /></p>
<p><label for="kelamin">Kelamin</label>
<label><input name="kelamin" type="radio" value="Laki-laki" checked>Laki-laki</label>
<label><input type="radio" name="kelamin" value="Perempuan">Perempuan</label><br /></p>
<p><label for="agama">Agama</label>
<select name="agama" id="agama">
<option>Islam</option>
<option>Kristen Protestan</option>
<option>Kristen Khatolik</option>
<option>Budha</option>
<option>Hindu</option>
</select><br /></p>
<p><label for="id_penghuni">ID Penghuni</label>
<?php
$result = mysql_query("select * from perusahaan");
echo '<select name="id_perusahaan">';
echo '<option>pilih</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['id_perusahaan'] . '">' . $row['nama_perusahaan'] . '</option>';
}
echo '</select>';
?>
<!-- kode selanjutnya---->
erwan
· Oct 16, 2012
· 0 Suka
· 0 Tidak Suka
Wah Top deh buat Mas Ellyx..memang master la..
erwan
· Oct 16, 2012
· 0 Suka
· 0 Tidak Suka
Mas ellyx kalo mau update untuk script dibawah ini tgl_lahir dan Id_perusahaannya, kelamin, agama, status kerja nggak muncul valuenya sesuai dengan kita simpan kedalam database dan ketika saya ubah kok nggak mau berubah datanya , Tolong ya master...thank's
<fieldset>
<form action = 'aksi_penghuni.php?module=user&act=update' method='post' onsubmit='return ValidateForm(this)'>
<?php
$edit = mysql_query("SELECT * from tblpenghuni WHERE id_penghuni='$_GET[id]'");
if ($data = mysql_fetch_array($edit))
{
?>
<fieldset>
<form action = "aksi_penghuni.php?module=user&act=input" method="post" onsubmit='return ValidateForm(this)'>
<input type="hidden" name="id" value="<?php echo $data['id_penghuni']; ?>">
<p><label for="no_ktp">Nomor KTP</label>
<input type="text" name="no_ktp" size="20" maxlength="18" value="<?php echo $data['no_ktp']; ?>" onkeypress="return harusangka(event)"><br /></p>
<p><label for="nama_penghuni">Nama Penghuni</label>
<input type = "text" name = "nama_penghuni" size = "50" maxlength="50" value="<?php echo $data['nama_penghuni']; ?>"><br /></p>
<p><label for="tempat_lahir">Tempat Lahir</label>
<input type="text" name = "tempat_lahir" size="50" value="<?php echo $data['tempat_lahir']; ?>" maxlength="30"></input><br /></p>
<p><label for="tgl_lahir">Tanggal Lahir</label>
<select name="tanggal" value="<?php echo $data['tgl_lahir']; ?>">
<?php
for ($tgl=1; $tgl<=31; $tgl++) {
echo '<option value="'.sprintf('%02s', $tgl).'">'.$tgl.'</option>';
}
?>
</select>-
<select name="bulan">
<?php
$bulan=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
for($i=0;$i<12;$i++){
echo '<option value="'.sprintf('%02s', $i+1).'">'.$bulan[$i].'</option>';
}
?>
</select>
-<select name="tahun">
<?php
$thn_skrg=date("Y");
for ($thn=1970; $thn<=$thn_skrg; $thn++) {
echo "<option value=$thn> $thn </option>";
}
?>
</select> <br /></p>
<p><label for="kelamin">Kelamin</label>
<label><input name="kelamin" type="radio" value="<?php echo $data['kelamin']; ?>" value="Laki-laki" checked>Laki-laki</label>
<label><input type="radio" name="kelamin" value="<?php echo $data['kelamin']; ?>" value="Perempuan">Perempuan</label><br /></p>
<p><label for="agama">Agama</label>
<select name="agama" value="<?php echo $data['agama']; ?>" id="agama">
<option>Islam</option>
<option>Kristen Protestan</option>
<option>Kristen Khatolik</option>
<option>Budha</option>
<option>Hindu</option>
</select><br /></p>
<p><label for="id_perusahaan">ID Perusahaan</label>
<?php
$result = mysql_query("select * from perusahaan");
echo '<select name="id_perusahaan">';
echo '<option>pilih</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['id_perusahaan'] . '">' . $row['nama_perusahaan'] . '</option>';
}
echo '</select>';
?>
<p><label for="deposit">Deposit</label>
<input type = "text" name = "deposit" size = "30" maxlength="20" value="<?php echo $data['deposit']; ?> " onkeypress="return harusangka(event)"><br /></p>
<p><label for="status_kerja">Status Kerja</label>
<select name="status_kerja" id="status_kerja" value="<?php echo $data['status_kerja']; ?>" >
<option>Permanen</option>
<option>Kontrak</option>
</select><br /></p>
<p><label for="status_aktif">Status</label>
<select name="status_aktif" id="status_aktif" value="<?php echo $data['status_aktif']; ?>" >
<option>Aktif</option>
<option>Tidak aktif</option>
</select><br /></p>
<p><input type="submit" value="Simpan" class="formbutton"> <input type="reset" value="Batal" class="formbutton"></p>
</form>
</fieldset>
ini script updatenya:
//update penghuni
if($module=='user' AND $act=='update')
{
$no_ktp=$_POST['no_ktp'];
$nama_penghuni=$_POST['nama_penghuni'];
$tempat_lahir=$_POST['tempat_lahir'];
$tgl_lahir=$_POST['tahun'].'-'.$_POST['bulan'].'-'.$_POST['tanggal'];
$kelamin=$_POST['kelamin'];
$agama=$_POST['agama'];
$id_perusahaan=$_POST['id_perusahaan'];
$deposit=$_POST['deposit'];
$status_kerja=$_POST['status_kerja'];
$status_aktif=$_POST['status_aktif'];
$id=$_POST['id'];
$tgl_d=substr($tanggal,3,2);
$bln_d=substr($tanggal,0,2);
$thn_d=substr($tanggal,6,4);
$ttl="$tempat, $tgl_lahir";
$tgl_daftar="$thn_d-$bln_d-$tgl_d";
mysql_query("update tblpenghuni set no_ktp='$no_ktp',nama_penghuni='$nama_penghuni',tempat_lahir='$tempat_lahir',tgl_lahir='$tgl_lahir',kelamin='$kelamin',agama='$agama',id_perusahaan='$id_perusahaan',depsoit='$deposit',status_kerja='$status_kerja',status='$status_aktif' where id_penguni='$id'");
echo "<script>alert('Selamat anda telah berhasil mengubah data penghuni')</script>";
echo"<script>document.location.href=\"tampil_penghuni.php\";</script>";
//header('location: tampil_perusahaan.php');
}
<fieldset>
<form action = 'aksi_penghuni.php?module=user&act=update' method='post' onsubmit='return ValidateForm(this)'>
<?php
$edit = mysql_query("SELECT * from tblpenghuni WHERE id_penghuni='$_GET[id]'");
if ($data = mysql_fetch_array($edit))
{
?>
<fieldset>
<form action = "aksi_penghuni.php?module=user&act=input" method="post" onsubmit='return ValidateForm(this)'>
<input type="hidden" name="id" value="<?php echo $data['id_penghuni']; ?>">
<p><label for="no_ktp">Nomor KTP</label>
<input type="text" name="no_ktp" size="20" maxlength="18" value="<?php echo $data['no_ktp']; ?>" onkeypress="return harusangka(event)"><br /></p>
<p><label for="nama_penghuni">Nama Penghuni</label>
<input type = "text" name = "nama_penghuni" size = "50" maxlength="50" value="<?php echo $data['nama_penghuni']; ?>"><br /></p>
<p><label for="tempat_lahir">Tempat Lahir</label>
<input type="text" name = "tempat_lahir" size="50" value="<?php echo $data['tempat_lahir']; ?>" maxlength="30"></input><br /></p>
<p><label for="tgl_lahir">Tanggal Lahir</label>
<?php
$tglLahir = explode(' ', $data['tgl_lahir']);
$tglLahir = explode('-',$tglLahir[0]);
?>
<select name="tanggal">
<?php
for ($tgl=1; $tgl<=31; $tgl++) {
echo '<option value="'.sprintf('%02s', $tgl).'"'.(intval($tglLahir[2]) == $tgl ? ' selected="selected"' : '').'>'.$tgl.'</option>';
}
?>
</select>-
<select name="bulan">
<?php
$bulan=array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember");
for($i=0;$i<12;$i++){
echo '<option value="'.sprintf('%02s', $i+1).'"'.(intval($tglLahir[1) == $i+1 ? ' selected="selected"' : '').'>'.$bulan[$i].'</option>';
}
?>
</select>
-<select name="tahun">
<?php
$thn_skrg=date("Y");
for ($thn=1970; $thn<=$thn_skrg; $thn++) {
echo '<option value="'.$thn.'"'.(intval($tglLahir[0]) == $thn ? ' selected="selected"' : '').'>'. $thn .'</option>';
}
?>
</select> <br /></p>
<p><label for="kelamin">Kelamin</label>
<label><input name="kelamin" type="radio" <?php echo $data['kelamin'] == 'Laki-laki' ? ' checked ' :''; ?> value="Laki-laki"/>Laki-laki</label>
<label><input type="radio" name="kelamin" <?php echo $data['kelamin'] == 'Perempuan' ? ' checked ' : ''; ?> value="Perempuan"/>Perempuan</label><br /></p>
<p><label for="agama">Agama</label>
<select name="agama" id="agama">
<option <?php echo $data['agama']=='Islam' ? 'selected="selected"' : ''; ?>>Islam</option>
<option <?php echo $data['agama']=='Kristen Protestan' ? 'selected="selected"' : ''; ?>>Kristen Protestan</option>
<option <?php echo $data['agama']=='Kristen Khatolik' ? 'selected="selected"' : ''; ?>>Kristen Khatolik</option>
<option <?php echo $data['agama']=='Budha' ? 'selected="selected"' : ''; ?>>Budha</option>
<option <?php echo $data['agama']=='Hindu' ? 'selected="selected"' : ''; ?>>Hindu</option>
</select><br /></p>
<p><label for="id_perusahaan">ID Perusahaan</label>
<?php
$result = mysql_query("select * from perusahaan");
echo '<select name="id_perusahaan">';
echo '<option>pilih</option>';
while ($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['id_perusahaan'] . '"'.($data['id_perusahaan'] == $row['id_perusahaan'] ? ' selected="selected"' : '').'>' . $row['nama_perusahaan'] . '</option>';
}
echo '</select>';
?>
<p><label for="deposit">Deposit</label>
<input type = "text" name = "deposit" size = "30" maxlength="20" value="<?php echo $data['deposit']; ?> " onkeypress="return harusangka(event)"><br /></p>
<p><label for="status_kerja">Status Kerja</label>
<select name="status_kerja" id="status_kerja">
<option <?php echo $data['status_kerja'] == 'Permanen' ? 'selected="selected"' :''; ?>>Permanen</option>
<option <?php echo $data['status_kerja'] == 'Kontrak' ? 'selected="selected"' :''; ?>>Kontrak</option>
</select><br /></p>
<p><label for="status_aktif">Status</label>
<select name="status_aktif" id="status_aktif" value="<?php echo $data['status_aktif']; ?>" >
<option>Aktif</option>
<option>Tidak aktif</option>
</select><br /></p>
<p><input type="submit" value="Simpan" class="formbutton"> <input type="reset" value="Batal" class="formbutton"></p>
</form>
</fieldset>
PS: perbaiki cara kamu memposting pertanyaan!
erwan
· Oct 16, 2012
· 0 Suka
· 0 Tidak Suka
Sorry mas...soalnya ane baru tau kalo ada web yang bagus ni......by the way tak coba dulu scriptnya mas....
Thank's ya mas ellyx
untuk lain ke-38 ada salah, kurang tanda ]
echo '<option value="'.sprintf('%02s', $i+1).'"'.(intval($tglLahir[1) == $i+1 ? ' selected="selected"' : '').'>'.$bulan[$i].'</option>';
seharusnya
echo '<option value="'.sprintf('%02s', $i+1).'"'.(intval($tglLahir[1]) == $i+1 ? ' selected="selected"' : '').'>'.$bulan[$i].'</option>';