This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Jumat, 05 Juli 2019

Pembuatan CRUD menggunakan PHP MY SQL menyambungkan dengan database




Cara membuat Form 
Berikut secara singkat cara pembuatan coding database menggunakan PHP

Cara membuat script dibawah ini dengan menggunakan PHP yaa.


1.Tampil data

 <!DOCTYPE html>
<html>
<head>
<title>DAVID</title>
</head>
<body>
<h2 align="center">LIST PRODUK DAVID</h2>
<a href="inputdata.php">Tambah Data</a>
<table border="1" align="center">
<tr>
<th>kode produk</th>
<th>nama produk</th>
<th>jenis produk</th>
<th>stok</th>
<th>deskripsi</th>
<th>harga beli</th>
<th>harga jual</th>
<th>diskon</th>
<th>opsi</th>
</tr>
<?php
include 'koneksi.php';
$kode_produk=1101;
$data = mysqli_query($koneksi, "select * from produk");
while ($z = mysqli_fetch_array($data))
{
?>
<tr>
<td><?php echo $kode_produk; ?></td>
<td><?php echo $z ['nama_produk']; ?></td>
<td><?php echo $z ['jenis_produk']; ?></td>
<td><?php echo $z ['stok']; ?></td>
<td><?php echo $z ['deskripsi']; ?></td>
<td><?php echo $z ['harga_beli']; ?></td>
<td><?php echo $z ['harga_jual']; ?></td>
<td><?php echo $z ['diskon']; ?></td>
<td><a href="editdata.php?kode=<?php echo $z['kode_produk']; ?>">Edit</a></td>
<td><a href="hapusdata.php?kode=<?php echo $z['kode_produk']; ?>">Hapus</a></td>
</tr>
<?php
$kode_produk++;
}
  ?>
</table>

</body>
</html>

hasil yang kita dapat seperti gambar di bawah



2.koneksi

<?php
$koneksi = mysqli_connect("localhost","root","","nimanda_uas");


//check connection
if (mysqli_connect_errno())
  {
echo 'Koneksi database gagal ! ' .mysqli_connect_error;
  }
 ?>


hasil nya = menampilkan data di PHP my admin


3.input update
<!DOCTYPE html>
<html>
<head>
<title>INPUT DATA</title>
</head>
<body>
<form  method="post" action="aksi_simpan.php">
<table>
<tr>
<td>Nama Produk</td>
<td><input type="text" name="nama_produk"></td>
</tr>
<tr>
<td>Jenis Produk</td>
<td><input type="text" name="jenis_produk"></td>
</tr>
<tr>
<td>Stok</td>
<td><input type="text" name="stok"></td>
</tr>
<tr>
<td>Deskripsi</td>
<td><input type="text" name="deskripsi"></td>
</tr>
<tr>
<td>Harga Beli/dus</td>
<td><input type="text" name="harga_beli"></td>
</tr>
<tr>
<td>Harga Jual/dus</td>
<td><input type="text" name="harga_jual"></td>
</tr>
<tr>
<td>Diskon</td>
<td><input type="text" name="diskon"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="save" value="Simpan"></td>
</tr>
</table>


</form>
</body>
</html>












4.ubah data

<!DOCTYPE html>
<html>
<head>
<title>UPDATE DATA</title>
</head>
<body>
<?php
include 'koneksi.php';
$kode_produk = $_GET['kode'];

$q1 = mysqli_query($koneksi,"select * from produk where kode_produk='$kode_produk' ");
$z  = mysqli_fetch_array($q1);
 ?>
<form  method="post" action="aksi_update.php">
<table>
<tr>
<td>nama_produk</td>
<td><input type="hidden" name="idx" value="<?php echo $z['kode_produk']; ?>">
<input type="text" name="nama_produk" value="<?php echo $z['nama_produk'];?>"></td>
</tr>
<tr>
<td>jenis_produk</td>
<td><input type="text" name="jenis_produk" value="<?php echo $z['jenis_produk'];?>"></td>
</tr>
<tr>
<td>stok</td>
<td><input type="text" name="stok" value="<?php echo $z['stok']; ?>"></td>
</tr>
<tr>
<td>deskripsi</td>
<td><input type="text" name="deskripsi" value="<?php echo $z['deskripsi']; ?>"></td>
</tr>
<tr>
<td>harga_beli/dus</td>
<td><input type="text" name="harga_beli" value="<?php echo $z['harga_beli']; ?>"></td>
</tr>
<tr>
<td>harga_jual/dus</td>
<td><input type="text" name="harga_jual" value="<?php echo $z['harga_jual']; ?>"></td>
</tr>
<tr>
<td>diskon</td>
<td><input type="text" name="diskon" value="<?php echo $z['diskon']; ?>"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="save" value="Update"></td>
</tr>
</table>


</form>
</body>
</html>






<?php include 'koneksi.php';
$kode_produk = $_GET['kode'];
mysqli_query($koneksi,"delete from produk where kode_produk='$kode_produk' ");
header('location:tampilan.php');?>

Taraaaa selesai gaes.. dicoba yaaa dengan teliti.
Thankyou!! 
Smoga bermanfaat