├── README.md ├── crud_gc.sql ├── edit_produk.php ├── gambar ├── 219-277-contoh.jpg └── 489-contoh.jpg ├── index.php ├── indomie.jpg ├── koneksi.php ├── miesedap.jpg ├── proses_edit.php ├── proses_hapus.php ├── proses_tambah.php └── tambah_produk.php /README.md: -------------------------------------------------------------------------------- 1 | # crud-php7 2 | 3 | Tutorial Selengkapnya bisa di lihat pada website saya https://gilacoding.com/ 4 | untuk youtube bisa di https://youtube.com/gilacoding 5 | 6 | Terimakasih 7 | -------------------------------------------------------------------------------- /crud_gc.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.8.4 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Waktu pembuatan: 11 Nov 2019 pada 08.25 7 | -- Versi server: 10.1.37-MariaDB 8 | -- Versi PHP: 7.1.30 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET AUTOCOMMIT = 0; 12 | START TRANSACTION; 13 | SET time_zone = "+00:00"; 14 | 15 | 16 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 17 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 18 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 19 | /*!40101 SET NAMES utf8mb4 */; 20 | 21 | -- 22 | -- Database: `crud_gc` 23 | -- 24 | 25 | -- -------------------------------------------------------- 26 | 27 | -- 28 | -- Struktur dari tabel `produk` 29 | -- 30 | 31 | CREATE TABLE `produk` ( 32 | `id` int(11) NOT NULL, 33 | `nama_produk` varchar(255) DEFAULT NULL, 34 | `deskripsi` text, 35 | `harga_beli` int(11) DEFAULT NULL, 36 | `harga_jual` int(11) DEFAULT NULL, 37 | `gambar_produk` varchar(255) DEFAULT NULL 38 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1; 39 | 40 | -- 41 | -- Dumping data untuk tabel `produk` 42 | -- 43 | 44 | INSERT INTO `produk` (`id`, `nama_produk`, `deskripsi`, `harga_beli`, `harga_jual`, `gambar_produk`) VALUES 45 | (1, 'Indomie', 'indomie ini enak sekali sob', 4000, 5000, '489-contoh.jpg'), 46 | (4, '342', '', 55, 234, '452-761-277-contoh.jpg'), 47 | (5, '123', '33', 55, 123, '623-452-761-277-contoh.jpg'), 48 | (6, '23', '44', 5, 234, '857-277-contoh.jpg'); 49 | 50 | -- 51 | -- Indexes for dumped tables 52 | -- 53 | 54 | -- 55 | -- Indeks untuk tabel `produk` 56 | -- 57 | ALTER TABLE `produk` 58 | ADD PRIMARY KEY (`id`); 59 | 60 | -- 61 | -- AUTO_INCREMENT untuk tabel yang dibuang 62 | -- 63 | 64 | -- 65 | -- AUTO_INCREMENT untuk tabel `produk` 66 | -- 67 | ALTER TABLE `produk` 68 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; 69 | COMMIT; 70 | 71 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 72 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 73 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 74 | -------------------------------------------------------------------------------- /edit_produk.php: -------------------------------------------------------------------------------- 1 | alert('Data tidak ditemukan pada database');window.location='index.php';"; 23 | } 24 | } else { 25 | // apabila tidak ada data GET id pada akan di redirect ke index.php 26 | echo ""; 27 | } 28 | ?> 29 | 30 | 31 | 32 | CRUD Produk dengan gambar - Gilacoding 33 | 77 | 78 | 79 |
80 |

Edit Produk

81 |
82 |
83 |
84 | 85 | 86 |
87 | 88 | 89 |
90 |
91 | 92 | 93 |
94 |
95 | 96 | 97 |
98 |
99 | 100 | 101 |
102 |
103 | 104 | 105 | 106 | Abaikan jika tidak merubah gambar produk 107 |
108 |
109 | 110 |
111 |
112 |
113 | 114 | -------------------------------------------------------------------------------- /gambar/219-277-contoh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herziwp/crud-php7/943e8692f3be4185b5ca72ca2d7631a8f2079b6f/gambar/219-277-contoh.jpg -------------------------------------------------------------------------------- /gambar/489-contoh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herziwp/crud-php7/943e8692f3be4185b5ca72ca2d7631a8f2079b6f/gambar/489-contoh.jpg -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | CRUD Produk dengan gambar - Gilacoding 9 | 47 | 48 | 49 |

Data Produk

50 |
+   Tambah Produk
51 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 93 | 94 | 95 | 99 | 100 |
NoProdukDekripsiHarga BeliHarga JualGambarAction
...Rp Rp 90 | Edit | 91 | Hapus 92 |
101 | 102 | -------------------------------------------------------------------------------- /indomie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herziwp/crud-php7/943e8692f3be4185b5ca72ca2d7631a8f2079b6f/indomie.jpg -------------------------------------------------------------------------------- /koneksi.php: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /miesedap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/herziwp/crud-php7/943e8692f3be4185b5ca72ca2d7631a8f2079b6f/miesedap.jpg -------------------------------------------------------------------------------- /proses_edit.php: -------------------------------------------------------------------------------- 1 | alert('Data berhasil diubah.');window.location='index.php';"; 35 | } 36 | } else { 37 | //jika file ekstensi tidak jpg dan png maka alert ini yang tampil 38 | echo ""; 39 | } 40 | } else { 41 | // jalankan query UPDATE berdasarkan ID yang produknya kita edit 42 | $query = "UPDATE produk SET nama_produk = '$nama_produk', deskripsi = '$deskripsi', harga_beli = '$harga_beli', harga_jual = '$harga_jual'"; 43 | $query .= "WHERE id = '$id'"; 44 | $result = mysqli_query($koneksi, $query); 45 | // periska query apakah ada error 46 | if(!$result){ 47 | die ("Query gagal dijalankan: ".mysqli_errno($koneksi). 48 | " - ".mysqli_error($koneksi)); 49 | } else { 50 | //tampil alert dan akan redirect ke halaman index.php 51 | //silahkan ganti index.php sesuai halaman yang akan dituju 52 | echo ""; 53 | } 54 | } 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /proses_hapus.php: -------------------------------------------------------------------------------- 1 | alert('Data berhasil dihapus.');window.location='index.php';"; 15 | } -------------------------------------------------------------------------------- /proses_tambah.php: -------------------------------------------------------------------------------- 1 | alert('Data berhasil ditambah.');window.location='index.php';"; 34 | } 35 | 36 | } else { 37 | //jika file ekstensi tidak jpg dan png maka alert ini yang tampil 38 | echo ""; 39 | } 40 | } else { 41 | $query = "INSERT INTO produk (nama_produk, deskripsi, harga_beli, harga_jual, gambar_produk) VALUES ('$nama_produk', '$deskripsi', '$harga_beli', '$harga_jual', null)"; 42 | $result = mysqli_query($koneksi, $query); 43 | // periska query apakah ada error 44 | if(!$result){ 45 | die ("Query gagal dijalankan: ".mysqli_errno($koneksi). 46 | " - ".mysqli_error($koneksi)); 47 | } else { 48 | //tampil alert dan akan redirect ke halaman index.php 49 | //silahkan ganti index.php sesuai halaman yang akan dituju 50 | echo ""; 51 | } 52 | } 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /tambah_produk.php: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | CRUD Produk dengan gambar - Gilacoding 9 | 53 | 54 | 55 |
56 |

Tambah Produk

57 |
58 |
59 |
60 |
61 | 62 | 63 |
64 |
65 | 66 | 67 |
68 |
69 | 70 | 71 |
72 |
73 | 74 | 75 |
76 |
77 | 78 | 79 |
80 |
81 | 82 |
83 |
84 |
85 | 86 | --------------------------------------------------------------------------------