-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproses_edit.php
More file actions
53 lines (39 loc) · 1.86 KB
/
Copy pathproses_edit.php
File metadata and controls
53 lines (39 loc) · 1.86 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
include('koneksi.php');
$id = $_POST['id'];
$nama_produk = $_POST['nama_produk'];
$deskripsi = $_POST['deskripsi'];
$harga_beli = $_POST['harga_beli'];
$harga_jual = $_POST['harga_jual'];
$gambar_produk = $_FILES['gambar_produk']['name'];
if($gambar_produk != ""){
$ekstensi_diperbolehkan = array('png', 'jpg');
$x = explode('.', $gambar_produk);
$ekstensi = strtolower(end($x));
$file_tmp = $_FILES['gambar_produk']['tmp_name'];
$angka_acak = rand(1, 999);
$nama_gambar_baru = $angka_acak.'-'.$gambar_produk;
if(in_array($ekstensi, $ekstensi_diperbolehkan) === true){
move_uploaded_file($file_tmp, 'gambar/'.$nama_gambar_baru);
$query = "UPDATE produk SET nama_produk= '$nama_produk', deskripsi='$deskripsi', harga_beli='$harga_beli', harga_jual='$harga_jual', gambar_produk='$nama_gambar_baru'";
$query .= "WHERE id = $id";
$result = mysqli_query($koneksi, $query);
if(!$result){
die("Query Eror: ".mysqli_error($koneksi)." - ".mysqli_error($koneksi));
} else {
echo "<script>alert('Data berhasil diubah!');window.location='index.php'</script>";
}
} else {
echo "<script>alert('Ekstensi gambar hanya bisa jpg dan png! ');window.location='edit_produk.php'</script>";
}
} else {
$query = "UPDATE produk SET nama_produk= '$nama_produk', deskripsi='$deskripsi', harga_beli='$harga_beli', harga_jual='$harga_jual'";
$query .= "WHERE id = $id";
$result = mysqli_query($koneksi, $query);
if(!$result){
die("Query Eror: ".mysqli_error($koneksi)." - ".mysqli_error($koneksi));
} else {
echo "<script>alert('Data berhasil diubah!');window.location='index.php'</script>";
}
}
?>