Nomor 1
<?php
$kd = $_GET['kode'];
$query = $koneksi->query("SELECT * FROM barang WHERE KdBrg='$kd'");
$ambil = mysqli_fetch_array($query);
?>
<style>
.button {
background-color: black;
border-style: solid;
border-color: coral;
color: white;
padding: 10px 15px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
</style>
<form method="POST">
<h1>Ubah Data Barang</h1>
<table>
<tr>
<td>Kode Barang :</td>
<td><input type="text" name="" value="<?php echo $ambil['KdBrg'] ?>" readonly=""></td>
</tr>
<tr>
<td>Nama Barang :</td>
<td><input type="text" name="txtNm" value="<?php echo $ambil['NmBrg'] ?>"></td>
</tr>
<tr>
<td>Harga :</td>
<td><input type="text" name="txtHr" value="<?php echo $ambil['Harga'] ?>"" onkeyup="this.value=this.value.replace(/[^\d]/,'')"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="button" value="Ubah" name="btnUbah">
</td>
</tr>
</table>
</form>
<?php
if (isset($_POST["btnUbah"]))
{
#tampung ke variabel yang isian dari form
$kode = $_POST["txtKd"];
$nama = $_POST["txtNm"];
$harga = $_POST["txtHr"];
#coba cek ada gak isinya
echo $kode . $nama . $harga;
$query = $koneksi->query("UPDATE barang SET NmBrg='$nama', Harga='$harga' WHERE KdBrg='$kd'") or die(mysqli_error($koneksi));
echo "<script>alert('Data berhasil diubah')</script>";
echo "<script>location = 'index.php?hal=tampil.php'</script>";
} #akhir tombol simpan diklik
?>