2. Membuat Config Pada PHP
1
2
3
4
5
6
7
8
9
10
11
| <?php $koneksi = mysqli_connect("localhost","root","","imalia_uas"); // check connection if (mysqli_connect_errno()) { echo 'koneksi database gagal !'.mysqli_connect_error; } ?> |
3. Menampilkan Data Dari Database
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| <!DOCTYPE html> <html> <head> <title>Imalia Ika Marista</title> </head> <body> <h2 align="center">crud data base produk</h2> <a href="inputdata.php">tambah data</a> <table border="5" 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> </tr> <?php include 'koneksi.php'; $kode_produk=100; $data = mysqli_query($koneksi,"select * from produk"); while($z = mysqli_fetch_array($data)) { ?> <tr align="center"> <td><?php echo $kode_produk; ?></td> <td align="left"><?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="form_editdata.php?kode=<?php echo $z['kode_produk']; ?>">edit</a> <a href="hapusdata.php?kode=<?php echo $z['kode_produk']; ?>">hapus</a> </td> </tr> <?php $kode_produk++; } ?> </table> </body> </html> |
3. Menambahkan Data Ke Dalam Database
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| s<!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</td> <td><input type="text" name="harga_beli"></td> </tr> <tr> <td>harga jual</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> </body> </html> |
Dengan penambahan script sebagai tujuan penyimpanan ke database maka saya menambahkan script dibawah ini dengan nama aksi_simpan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| <?php include 'koneksi.php'; $a = $_POST['nama_produk']; $b = $_POST['jenis_produk']; $c = $_POST['stok']; $d = $_POST['deskripsi']; $e = $_POST['harga_beli']; $f = $_POST['harga_jual']; $g = $_POST['diskon']; mysqli_query($koneksi,"insert into produk (nama_produk,jenis_produk,stok,deskripsi,harga_beli,harga_jual,diskon) values ('$a','$b','$c','$d','$e','$f','$g')"); header('location:tampil.php'); ?> |
Maka hasil kolom akan seperti ini
4. Mengedit Data yang terdapat dalam Database
saya beri nama form_editdata.php
saya beri nama form_editdata.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
| <!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</td> <td><input type="text" name="harga_beli" value="<?php echo $z['harga_beli']; ?>"></td> </tr> <tr> <td>harga jual</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> </body> </html> |
lalu untuk menjalankan saya membuat script baru dengan nama aksi_update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
| <?php include 'koneksi.php'; $kode_produk = $_POST['idx']; $a = $_POST['nama_produk']; $b = $_POST['jenis_produk']; $c = $_POST['stok']; $d = $_POST['deskripsi']; $e = $_POST['harga_beli']; $f = $_POST['harga_jual']; $g = $_POST['diskon']; mysqli_query($koneksi,"update produk set nama_produk='$a',jenis_produk='$b', stok='$c', deskripsi='$d', harga_beli='$e', harga_jual='$f', diskon='$g' where kode_produk='$kode_produk' "); header('location:tampil.php'); ?> |
Sebelum Ditambah Data
Tambah Data
Hasil Simpan
Mengedit NIKON Menjadi ACER
Hasil Update
KALO MAU KULIAH JANGAN MASUK JURUSAN TI(TEKNIK INFORMATIKA),,,SUSAH TIDUR MALAM MIKIRIN KODING!!!!!!!
KAMU TIDAK AKAN KUAT BIAR AKU SAJA
Tidak ada komentar:
Posting Komentar