-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic-input-barang.php
40 lines (33 loc) · 1.14 KB
/
logic-input-barang.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
include 'conn.php';
if (isset($_POST['submit'])) {
// Ambil data dari form
$barang_kode = $_POST['kodeBarang'];
$barang_nama = $_POST['namaBarang'];
$barang_harga = $_POST['hargaBarang'];
// Proses upload foto
$barang_foto = $_FILES['fotoBarang']['name'];
$tmp_foto = $_FILES['fotoBarang']['tmp_name'];
$path_foto = "uploadFoto/" . $barang_foto;
// Pindahkan file yang diupload
if (move_uploaded_file($tmp_foto, $path_foto)) {
// insert data
$query = $conn->query("INSERT INTO tb_barang (barang_kode, barang_nama, barang_harga, barang_foto) VALUES ('$barang_kode', '$barang_nama', '$barang_harga', '$barang_foto')");
if ($query == true) {
echo "<script>
alert('Data Berhasil Disimpan');
window.location='view-barang.php'
</script>";
} else {
echo "<script>
alert('Data Gagal Disimpan');
window.location='view-barang.php'
</script>";
}
} else {
echo "<script>
alert('Foto Gagal Disimpan');
window.location='view-barang.php'
</script>";
}
}