Nama Database: toko_qu
Nama Tabel : barang
Design Table: barang |
Nama File : barang.php
<html>
<head>
<title>Input Barang</title>
</head>
<body>
<?
//---Membuat koneksi ke server ----
$server='localhost';
$uid='root';$pass='password';
$database='toko_qu'; //Nama Database yang digunakan
mysql_connect($server,$uid,$pass) or die("Gagal koneksi ke Server");
mysql_select_db($database)or die("Database tidak ditemukan");
//---------------------------------
if(isset($_POST['btnSubmit'])){
$nama_brg=$_POST['txtNama']; $kategori=$_POST['optKategori'];
$harga=$_POST['txtHarga']; $satuan=$_POST['cbSatuan'];
/*---Membuat Perintah SQL INSERT---
untuk menambahkan data pada tabel barang
------------------------------------------*/
$ssql="INSERT INTO barang(nama_brg, kategori, harga, satuan)
VALUES('$nama_brg','$kategori','$harga','$satuan')";
$result=mysql_query($ssql)or die("Error SQL \n".mysql_error());
if ($result){
$status="Data berhasil Disimpan";
}
}
?>
<form name="FrmBarang" id="FrmBarang" method="post">
<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td>
Nama Barang
</td>
<td>
<input type="text" name="txtNama" size="30">
</td>
</tr>
<tr>
<td>
Kategori
</td>
<td>
<label><input type="radio" name="optKategori" value="Hardware">Hardware</label>
<label><input type="radio" name="optKategori" value="Software">Software</label>
</td>
</tr>
<tr>
<td>
Harga
</td>
<td>
<input type="text" name="txtHarga" size="10">
</td>
</tr>
<tr>
<td>
Satuan
</td>
<td>
<select name="cbSatuan">
<option value="Unit">Unit</option>
<option value="Paket">Paket</option>
<option value="Pcs">Pcs</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="btnSubmit" value="Submit">
<input type="reset" name="btnReset" value="Cancel">
</td>
</tr>
<tr>
<td colspan="2" align=center>
<?php echo $status;?>
</td>
</tr>
</table>
</form>
</body>
</html>
0 comments:
Post a Comment