simpan.php

Rheyank Iwan Nytt · Jul 12, 2012
mas mw nx nech... stelah q input data.. trs kok d halamanx simpan.php tu ksong ??? hrusnya kan keluar alert "data berhasil disimpan" trs mnju ke tampil.php

tp kmrn punya q gag bsa mas..

ne coding input nya
<FORM ACTION="simpan.php" METHOD="POST" NAME="input">
<table width="774" border="0" align="center" cellpadding="0" cellspacing="0">
			
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td width="589">&nbsp;</td>
	  </tr>
			<tr>
			  <td width="20" height="29">&nbsp;</td>
				<td width="165">ID Pelanggan</td>
				<td><input type="text" name="id_pel" size="20" maxlength="15"></td>
			</tr>
			<tr>
			  <td height="30">&nbsp;</td>
				<td>Nama</td>
				<td><input type="text" name="nama" size="30" maxlength="30"></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>Alamat</td>
				<td><textarea name="alamat" cols="40" rows="3"></textarea></td>
			</tr>
			<tr>
			  <td height="32">&nbsp;</td>
			    <td>Tarif/Daya</td>
				<td><select name="tarif" id="tarif" class=""><option value="450">450</option><option value="900">900</option>
				<option value="1300">1300</option><option value="2200">2200</option><option value="3500">3500</option>
				<option value="4400">4400</option><option value="5500">5500</option><option value="6600">6600</option></select> 
					/ 
				<select name="daya" id="daya" class=""><option value="R1">R1</option><option value="R1T">R1T</option><option value="B1">B1</option>
				<option value="B1T">B1T</option><option value="S1">S1</option><option value="S1T">S1T</option>
				<option value="S2T">S2T</option></select>
				</td>
			</tr>
			<tr>
				<td height="28">&nbsp;</td>
				<td>Mutasi</td>
				<td><input type="radio" name="mutasi" value="Pasang Baru"> Pasang Baru &nbsp;&nbsp;
				<input type="radio" name="mutasi" value="Migrasi"> Migrasi &nbsp;&nbsp;
				<input type="radio" name="mutasi" value="Ganti Tarif"> Ganti Tarif &nbsp;&nbsp;
				<input type="radio" name="mutasi" value="Tambah Daya"> Tambah Daya</td>
			</tr>
			<tr>
			  <td height="32">&nbsp;</td>
				<td>Rak/Loker</td>
				<td><select name="Rak">
				<? //Menampilkan Rak dari 1 - 5
					for ($i=1; $i<=5; $i++) {
						$tg = ($i<1) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
				</select> /
				  <select name="loker">
				<? //Menampilkan loker 1 - 400
					for ($i=1; $i<=400; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
				</select>				</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>Keterangan</td>
				<td><textarea name="keterangan" cols="40" rows="3"></textarea></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>&nbsp;</td>
			  <td>&nbsp;</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;&nbsp;
				  <input type="submit" name="Tambah" value="Tambah">				  &nbsp;
				<input type="reset" name="reset" value="Reset"></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
    </tr>
		</table>
	</FORM>

ne coding simpannya mas
<?
//Cek Tombol 
if ($_POST['Submit'] == "Submit") {
//Kirimkan Variabel
$id_pel = $_POST['id_pel'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$tarif_daya = $_POST['tarif']."/".$_POST['daya'];
$mutasi = $_POST['mutasi'];
$rak_loker = $_POST['rak']."/".$_POST['loker'];
$keterangan = $_POST['keterangan'];

//validasi data jika nama dan pesan kosong
if (empty($_POST['id_pel'])|| empty($_POST['nama'])) 
{
?>
<script language="JavaScript">
alert('Data Harap Dilengkapi');
document.location='index.php?page=input';
</script>
<?
}
//Jika Validasi Terpenuhi
else
{
//Memanggil File Koneksi Database
include "koneksi.php";

//Masukan data ke Table dt_pel
$tambah="INSERT INTO dt_pel VALUES('$id_pel','$nama','$alamat','$daya_tarif','$mutasi','$rak_loker','$keterangan')";
$kueri_tbh=mysql_db_query($db,$tambah,$conn_db);
if ($kueri_tbh)
{
//Jika Sukses
//echo "Data telah diinput";
//echo"<meta http-equiv='refresh' content='0;url=index.php?page=tampil'>";
?>
<script language="JavaScript">
alert('Data Berhasil diinput');
document.location='index.php?page=tampil';
</script>
<?

}
else
{
//Jika Gagal
echo "Data gagal diinput, Silakan Ulangi";
}
}
}
?>

mhon bantuannya ea mas....
thanks sblumnya....:)
Silahkan login untuk menjawab!
1
Loading...
Ellyx Christian · Jul 12, 2012 · 1 Suka · 0 Tidak Suka
sepertinya tinggal ganti
if ($_POST == "Submit") {
dengan
if($_POST){
0
Loading...
Rheyank Iwan Nytt · Jul 13, 2012 · 0 Suka · 0 Tidak Suka
thanks mas da bsa... tp untuk "Tarif/Daya n Rak" nya gag keluar hasilnya mas...
pdahal uda sya isi
0
Loading...
Ellyx Christian · Jul 13, 2012 · 0 Suka · 0 Tidak Suka
bisa jadi file tampil.php-mu yang salah
0
Loading...
Rheyank Iwan Nytt · Jul 15, 2012 · 0 Suka · 0 Tidak Suka
mngkin mas..
ne tk kc scriptnya... tlong d priksa ea mas....

tampil.php
<div id="content">
	<h2 align="center">Data Pelanggan</h2>
	<table width="102%" border="0" align="center" cellpadding="0" cellspacing="0"  id="tabel">
	<tr bgcolor="#8BB2D9">
		<th width="3%" height="39">No</td>
		<th width="20%">ID Pelanggan</td>
		<th width="15%">Nama</td>
		<th width="14%">Alamat</td>
		<th width="9%">Tarif_Daya</td>
		<th width="8%">Mutasi</td>
		<th width="9%">Rak_Loker</td>
		<th width="15%">Keterangan</td>
	  <th width="7%">Action</td>      
	</tr>
	<?
	include "koneksi.php";
	$sql="SELECT * FROM dt_pel ORDER BY id_pel";
	$tampil = mysql_query($sql);
    while (	$hasil = mysql_fetch_array ($tampil)) {
			$id_pel = stripslashes ($hasil['id_pel']);
			$nama = stripslashes ($hasil['nama']);
			$alamat = stripslashes ($hasil['alamat']);
			$tarif_daya = stripslashes ($hasil['tarif_daya']);
			$mutasi = stripslashes ($hasil['mutasi']);
			$rak_loker = stripslashes ($hasil['rak_loker']);
			$keterangan = stripslashes ($hasil['keterangan']);
      {
		$no++;
	?>
		<tr align="center">
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td bgcolor="#CCCCCC">&nbsp;</td>
	  </tr>
		<tr align="center">
			<td><?=$no?>
		    <div align="center"></div></td>
			<td><?=$id_pel?>
		    <div align="center"></div></td>
			<td><?=$nama?>
		    <div align="center"></div></td>
			<td><?=$alamat?>
		    <div align="center"></div></td>
			<td><?=$tarif_daya?>
		    <div align="center"></div></td>
			<td><?=$mutasi?>
		    <div align="center"></div></td>
			<td><?=$rak_loker?>
		    <div align="center"></div></td>
			<td><?=$keterangan?>
		    <div align="center"></div></td>
		  <td bgcolor="#CCCCCC"><div align="center"><a href="index.php?page=edit&id_pel=<?=$id_pel?>">Edit</a></div></td>
	    </tr>
		<tr align="center">
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td> 
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>
		  <td>&nbsp;</td>		  
		  <td>&nbsp;</td>
		  <td bgcolor="#CCCCCC">&nbsp;</td>
	  </tr>
	<?  
	}}
	?>
  </table>
</div>


oea mas... kmrin q coba input data,, tp mncul alert "data harap dilengkapi".. pdhal q uda lengkapi semua..
np ea mas..

ni q sertain codingnya mas..
input.php
<FORM ACTION="simpan.php" METHOD="POST" NAME="input">
<table width="774" border="0" align="center" cellpadding="0" cellspacing="0">
			
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td width="589">&nbsp;</td>
	  </tr>
			<tr>
			  <td width="20" height="29">&nbsp;</td>
				<td width="165">ID Pelanggan</td>
				<td><input type="text" name="id_pel" size="25" maxlength="20"></td>
			</tr>
			<tr>
			  <td height="30">&nbsp;</td>
				<td>Nama</td>
				<td><input type="text" name="nama" size="30" maxlength="30"></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>Alamat</td>
				<td><textarea name="alamat" cols="40" rows="3"></textarea></td>
			</tr>
			<tr>
			  <td height="32">&nbsp;</td>
			    <td>Tarif/Daya</td>
				<td><select name="tarif" id="tarif" class=""><option value="450">450</option><option value="900">900</option>
				<option value="1300">1300</option><option value="2200">2200</option><option value="3500">3500</option>
				<option value="4400">4400</option><option value="5500">5500</option><option value="6600">6600</option></select> 
					/ 
				<select name="daya" id="daya" class=""><option value="R1">R1</option><option value="R1T">R1T</option><option value="B1">B1</option>
				<option value="B1T">B1T</option><option value="S1">S1</option><option value="S1T">S1T</option>
				<option value="S2T">S2T</option></select>
				</td>
			</tr>
			<tr>
				<td height="28">&nbsp;</td>
				<td>Mutasi</td>
				<td><input type="radio" name="mutasi" value="Pasang Baru"> Pasang Baru &nbsp;&nbsp;
				<input type="radio" name="mutasi" value="Migrasi"> Migrasi &nbsp;&nbsp;
				<input type="radio" name="mutasi" value="Tambah Daya"> Tambah Daya</td>
			</tr>
			<tr>
			  <td height="32">&nbsp;</td>
				<td>Rak/Loker</td>
				<td><select name="Rak">
				<? //Menampilkan Rak dari 1 - 5
					for ($i=1; $i<=5; $i++) {
						$tg = ($i<1) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
				</select> /
				  <select name="loker">
				<? //Menampilkan loker 1 - 400
					for ($i=1; $i<=400; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
				</select>				</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>Keterangan</td>
				<td><textarea name="keterangan" cols="40" rows="3"></textarea></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>&nbsp;</td>
			  <td>&nbsp;</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;&nbsp;
				  <input type="submit" name="Tambah" value="Tambah">				  &nbsp;
				<input type="reset" name="reset" value="Reset"></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
    </tr>
		</table>
	</FORM>

simpan.php
<?
//Cek Tombol 
if ($_POST){
//Kirimkan Variabel
$id_pel = $_POST['id_pel'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$tarif_daya = $_POST['tarif']."/".$_POST['daya'];
$mutasi = $_POST['mutasi'];
$rak_loker = $_POST['rak']."/".$_POST['loker'];
$keterangan = $_POST['keterangan'];

//validasi data jika nama dan pesan kosong
if (empty($_POST['id_pel'])|| empty($_POST['nama'])|| empty($_POST['alamat'])|| empty($_POST['tarif'])|| empty($_POST['daya'])|| empty($_POST['mutasi'])|| empty($_POST['rak'])|| empty($_POST['loker'])|| empty($_POST['keterangan'])) 
{
?>
<script language="JavaScript">
alert('Data Harap Dilengkapi');
document.location='index.php?page=input';
</script>
<?
}
//Jika Validasi Terpenuhi
else
{
//Memanggil File Koneksi Database
include "koneksi.php";

//Masukan data ke Table dt_pel
$tambah="INSERT INTO dt_pel VALUES('$id_pel','$nama','$alamat','$tarif_daya','$mutasi','$rak_loker','$keterangan')";
$query_tambah=mysql_db_query($db,$tambah,$conn_db);
if ($query_tambah)
{
//Jika Sukses
//echo "Data telah diinput";
//echo"<meta http-equiv='refresh' content='0;url=index.php?page=tampil'>";
?>
<script language="JavaScript">
alert('Data Berhasil diinput');
document.location='index.php?page=tampil';
</script>
<?

}
else
{
//Jika Gagal
echo "Data gagal diinput, Silakan Ulangi";
}
}
}
?>

skalian editnya jga ea mas...
edit.php
<?php
include "koneksi.php";

if (isset($_GET['id_pel'])) {
	$id_pel = $_GET['id_pel'];
} else {
	die ("Error. No id_pel Selected! ");	
}
//Tampilkan datanya
$query = "SELECT id_pel,nama,alamat,tarif_daya,mutasi,rak_loker,keterangan FROM dt_pel WHERE id_pel='$id_pel'";
$sql = mysql_query ($query);
$hasil = mysql_fetch_array ($sql);
$id_pel = $hasil['id_pel'];
$nama = $hasil['nama'];
$alamat = $hasil['alamat'];
//Memecah tarif/daya
list($tarif,$daya) = explode ("/",$hasil['tarif_daya']);
$mutasi = $hasil['mutasi'];
//Memecah rak/loker
list($rak,$loker) = explode ("/",$hasil['rak_loker']);
$keterangan = $hasil['keterangan'];
//proses edit 
if (isset($_POST['Edit'])) {
$id_pel = $_POST['id_pel'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$tarif_daya = $_POST['tarif']."/".$_POST['daya'];
$mutasi = $_POST['mutasi'];
$rak_loker = $_POST['rak']."/".$_POST['loker'];
$keterangan = $_POST['keterangan'];
		//update data
	$query = "UPDATE dt_pel SET nama='$nama',alamat='$alamat',tarif_daya='$tarif_daya',
			  mutasi='$mutasi',rak_loker='$rak_loker',keterangan='$keterangan' WHERE id_pel='$id_pel'";
	$sql = mysql_query ($query);
	if ($sql) {
		echo "<h2><font color=#8BB2D9><center>Data Pelanggan telah berhasil diedit</center></font></h2>";	
	} else {
		echo "<h2><font color=red><center>Data Pelanggan gagal diedit</center></font></h2>";	
	}
}
?>
<div id="content">
	<h2 align="center">Edit Data Pelanggan</h2>
	<FORM ACTION="" METHOD="POST" NAME="input">
		<table cellpadding="0" cellspacing="0" border="0" width="700">
			
			<tr>
			  <td width="18">&nbsp;</td>
				<td width="132" height="24">ID Pelanggan</td>
				<td width="550">:<b><?=$id_pel?>
				  <input type="hidden" name="nip" value="<?=$id_pel?>">
				</b></td>
			</tr>
			<tr>
			  <td height="30">&nbsp;</td>
				<td>Nama</td>
				<td><input type="text" name="nama" size="30" maxlength="30" value="<?=$nama?>"></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>Alamat</td>
				<td><textarea name="alamat" cols="40" rows="5"><?=$alamat?></textarea></td>
			</tr>
			<tr>
			  <td height="32">&nbsp;</td>
			    <td>Tarif/Daya</td>
				<td><select name="tarif" id="tarif" class=""><option value="450">450</option><option value="900">900</option>
				<option value="1300">1300</option><option value="2200">2200</option><option value="3500">3500</option>
				<option value="4400">4400</option><option value="5500">5500</option><option value="6600">6600</option></select> 
					/ 
				<select name="daya" id="daya" class=""><option value="R1">R1</option><option value="R1T">R1T</option><option value="B1">B1</option>
				<option value="B1T">B1T</option><option value="S1">S1</option><option value="S1T">S1T</option>
				<option value="S2T">S2T</option></select>
				</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td height="28">Mutasi</td>
				<td><input type="radio" name="mutasi" value="Pasang Baru" <? echo ($mutasi==PasangBaru)?"checked":""; ?>> 
				Pasang Baru &nbsp;&nbsp;
				<input type="radio" name="mutasi" value="Migrasi" <? echo ($mutasi==Migrasi)?"checked":""; ?>> 
			    Migrasi &nbsp;&nbsp;				
			    <input type="radio" name="mutasi" value="Tambah Daya" <? echo ($mutasi==TambahDaya)?"checked":""; ?>> 
			    Tambah Daya</td>
			</tr>
			<tr>
			  <td height="32">&nbsp;</td>
				<td>Rak/Loker</td>
				<td><select name="Rak">
				<? //Menampilkan Rak dari 1 - 5
					for ($i=1; $i<=5; $i++) {
						$tg = ($i<1) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
				</select> /
				  <select name="loker">
				<? //Menampilkan loker 1 - 400
					for ($i=1; $i<=400; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
				</select>				</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>Keterangan</td>
				<td><textarea name="keterangan" cols="40" rows="3"></textarea></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
				<td>&nbsp;</td>
				<td>&nbsp;&nbsp;
				<input type="submit" name="Edit" value="Edit Data">&nbsp;
			  <input type="reset" name="reset" value="Reset"></td>
			</tr>
		</table>
	</FORM>
</div>




maaf ea mas lok terlalu banyak pertanyaan.. cs mc gag mudeng q...
thanks sblumnya....
0
Loading...
Ellyx Christian · Jul 17, 2012 · 0 Suka · 0 Tidak Suka
struktur tablenya seperti apa?
0
Loading...
Rheyank Iwan Nytt · Jul 18, 2012 · 0 Suka · 0 Tidak Suka
sblumnya q mnta maaf mas....
pertanyaaan q yg d atas uda bs mas..

tinggal "rak" di field "rak/loker" nya ja mas yg gag mw klwar..
trs untuk coding input, simpan sma tampil nya uda ada di atas mas...

mw nanya lg mas...
misalkan kita mengedit data,, otomatis data yg kita edit akan terupdate isinya..
trs yg sya tanyakan,, qta mengEdit data, tpi data lma gag berubah, cuma yg tampil tu data yg updatenya jaa... tu gmn mas codingnya??

ex:
data lama(sbelum di edit)
nip : 1234
nama : aku
alamat : gresik
keterangan : tinggal di gresik pda tgl 13-07-2012
data baru (setelah di edit)
nip : 1234
nama : aku
alamat : surabaya
keterangan : tinggal di surabaya pda tgl 20-07-2012

jd ktika qta mncari "nip 1234" akan mncul
nip : 1234
nama : aku
alamat : surabaya
keterangan : tinggal di gresik pda tgl 13-07-2012
tinggal di surabaya pda tgl 20-07-2012

gmn ea mas cranya???
0
Loading...
Ellyx Christian · Jul 19, 2012 · 0 Suka · 0 Tidak Suka
itu tablenya harus dipecah jadi dua, table yang mencatat nip, nama. Dan tabel yang mencatat alamat dan keterangan.
0
Loading...
Rheyank Iwan Nytt · Jul 20, 2012 · 0 Suka · 0 Tidak Suka
contohnya gmn mas...

ne struktur tabel q yg skrng...

id_pel (varchar 20)
nama (varchar 50)
alamat (varchar 100)
tarif_daya (varchar 10)
mutasi (varchar 10)
rak_loker (varchar 10)
keterangan (varchar 100)

untuk pemecahannya gmn mas ????
trs untuk primary key atw laennya pa jja mas ???
mhon bantuannya ea...
0
Loading...
Ellyx Christian · Jul 21, 2012 · 0 Suka · 0 Tidak Suka
table pelanggan
id_pel (varchar 20) *
nama (varchar 50)
tarif_daya (varchar 10)
mutasi (varchar 10)
rak_loker (varchar 10)

table alamat_pelanggan
id_alamat (int) autoinrement primary key
id_pel (varchar 20)
alamat (varchar 100)
keterangan (varchar 100)
tanggal (datetime)
0
Loading...
Rheyank Iwan Nytt · Jul 24, 2012 · 0 Suka · 0 Tidak Suka
thanks ea mas... lok q kurang jelas ntar tx lgi ...