- Beranda
- Komunitas
- Tech
- Programmer Forum
"help" cara edit data combobox yang datanya dari database


TS
hiruma94
"help" cara edit data combobox yang datanya dari database
tolong gan,.. pengennya waktu di klik tombol edit data yang di mau di edit dicombobox muncul,..
pengenya gini,..

ini codenya
sebelumnya terimakasih
pengenya gini,..

ini codenya
PHP Code:
<?php
require"koneksi.php";
require"cek.php";
require"menu.php";
if($_POST[submit])
{
if(empty($_POST[nm_tipe])) $msg="Nama tipe TIDAK BOLEH KOSONG !!!!!!";
else
{
//proses simpan
if (mysql_query("insert into tipe values ('','$_POST[nm_merk]','$_POST[nm_tipe]'<img src="https://s.kaskus.id/images/smilies/sumbangan/13.gif" data-sceditor-emoticon=";)" border="0" alt="emoticon-Wink" title="Wink"/>"))
{
$msg="Tipe $_POST[nm_tipe] BERHASIL DI SIMPAN !!!!";
header ("location:tipe.php?msg=$msg");
exit;
}
else {
$msg=" DATA $_POST[nm_tipe] GAGAL DI SIMPAN !!!!";
}
}
}
//proses update
elseif ($_POST[update])
{
mysql_query("UPDATE tipe SET nm_tipe='$_POST[nm_tipe]','nm_merk='$_POST[nm_merk]'
WHERE kd_tipe='$_POST[kd_tipe]' ");
{
$msg="Data $_POST[nm_tipe] berhasil di update";
header ("location:tipe.php?msg=$msg");
exit;
}
}
//menampilkan edit
elseif ($_GET[edit])
{
$dt=mysql_fetch_array(mysql_query("SELECT * FROM tipe WHERE kd_tipe='$_GET[edit]'"));
$kd_tipe=$dt[kd_tipe];
$nm_tipe=$dt[nm_tipe];
$nm_merk=$dt[nm_merk];
$kd_merk=$dt[kd_merk];
{
}
}
//hapus data
elseif ($_GET[del])
{
mysql_query("DELETE FROM tipe WHERE kd_tipe='$_GET[del]'");
$msg="Data $_GET[del] berhasil di hapus! ";
}
?>
<!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" />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<title>tipe</title>
</head>
<body >
<form action="" method="POST">
<p/>
<table width="492" border="0" class="td1" align="center">
<tr>
<td colspan="3" class="header td3" align="center">Input tipe</td>
</tr>
<tr>
<td colspan="3">
<center><?php echo $msg; ?><?php echo $_GET[msg] ?><br/></td>
</tr>
<tr>
<td width="86" align="center"><strong>Merk</strong></td>
<td width="3"><strong>:</strong></td>
<td width="381" valign="middle"><p>
<select name="kd_merk">
<option>-- pilih merk --</option>
<?php if (empty($kd_merk))
{ $query="SELECT kd_merk,nm_merk FROM merk ORDER BY nm_merk";
$sql=mysql_query($query);
while ($hasil = mysql_fetch_array($sql)){
$select=($hasil['kd_merk']==$kd_merk) ? "select" : "";
echo "<option value='$hasil[kd_merk]' $select>$hasil[nm_merk]</option>" ; }
}
else {
$query=" SELECT kd_merk,nm_merk FROM merk ";
$sql=mysql_query($query);
while ($hasil = mysql_fetch_array($sql)){
$select=($hasil['kd_merk']==$kd_merk) ? "select" : "";
echo "<option value='$hasil[kd_merk]' $select>$hasil[nm_merk]</option>"; }
}?>
</select>
<input name="kd_tipe" type="hidden" value="<?php echo $kd_tipe; ?>" />
</p></td>
</tr>
<tr>
<td align="center"><strong>Tipe</strong></td>
<td><strong>:</strong></td>
<td valign="middle"><p>
<input type="text" name="nm_tipe" size="45" value="<?php echo $nm_tipe;?>"/>
</p></td>
</tr>
<br/>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td colspan="3" align="center" valign="middle" class="header td3" height="40"><?php if(empty($_GET[edit])) { ?>
<input class="button"type="submit" name="submit" id="submit" value="submit" />
<?php } else { ?>
<input class="button" type="submit" name="update" id="update" value="update" />
<?php } ?>
<input class="button"type="reset" name="reset" id="reset" value="reset" /> <br/>
</td>
</tr>
</table>
<p> </p>
<table width="528" align="center" border="1" id="zebra" class="zebra" >
<tr class="headerT zebra ">
<th width="42" height="30"><div align="center">No</div></th>
<th width="78"><div align="center">Action</div></th>
<th width="117"><div align="center">tipe</div></th>
<th width="257"><div align="center">merk</div></th>
</tr>
<?php
$i=1;
$sql = mysql_query("SELECT * FROM tipe LEFT JOIN merk ON tipe.kd_merk=merk.kd_merk");
while ($data = mysql_fetch_array($sql)){
?>
<tr>
<td height="27" align=center><?php echo" $i" ?></td>
<td> <a href="<?php echo"tipe.php?edit=$data[kd_tipe]"; ?>"><img src="./image/b_edit.png " title="edit"/></a>
<a href="<?php echo"tipe.php?del=$data[kd_tipe]"; ?>"><img src="./image/b_drop.png" title="delete" /></a></td>
<td><?php echo" $data[nm_tipe]" ?></td>
<td><?php echo" $data[nm_merk]" ?></td>
</tr>
<?php $i++; } ?>
</table>
</form>
</body>
</html>
sebelumnya terimakasih
0
6.4K
1


Komentar yang asik ya
Urutan
Terbaru
Terlama


Komentar yang asik ya
Komunitas Pilihan