-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit.php
More file actions
72 lines (64 loc) · 1.79 KB
/
edit.php
File metadata and controls
72 lines (64 loc) · 1.79 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
// include database connection file
include_once("config.php");
// Check if form is submitted for user update, then redirect to homepage after update
if(isset($_POST['update']))
{
$id = $_POST['id'];
$name=$_POST['name'];
$keterangan=$_POST['keterangan'];
$harga=$_POST['harga'];
$jumlah=$_POST['jumlah'];
// update user data
$result = mysqli_query($mysqli, "UPDATE produk SET nama_produk='$name',keterangan='$keterangan',harga='$harga',jumlah='$jumlah' WHERE id=$id");
// Redirect to homepage to display updated user in list
header("Location: index.php");
}
?>
<?php
// Display selected user data based on id
// Getting id from url
$id = $_GET['id'];
// Fetech user data based on id
$result = mysqli_query($mysqli, "SELECT * FROM produk WHERE id=$id");
while($user_data = mysqli_fetch_array($result))
{
$name = $user_data['nama_produk'];
$keterangan = $user_data['keterangan'];
$harga = $user_data['harga'];
$jumlah = $user_data['jumlah'];
}
?>
<html>
<head>
<title>Edit Data Produk</title>
</head>
<body>
<a href="index.php">Home</a>
<br/><br/>
<form name="update_user" method="post" action="edit.php">
<table border="0">
<tr>
<td>Nama Produk</td>
<td><input type="text" name="name" value=<?php echo $name;?>></td>
</tr>
<tr>
<td>Keterangan</td>
<td><input type="text" name="keterangan" value=<?php echo $keterangan;?>></td>
</tr>
<tr>
<td>Harga</td>
<td><input type="text" name="harga" value=<?php echo $harga;?>></td>
</tr>
<tr>
<td>Jumlah</td>
<td><input type="text" name="jumlah" value=<?php echo $jumlah;?>></td>
</tr>
<tr>
<td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
<td><input type="submit" name="update" value="Update"></td>
</tr>
</table>
</form>
</body>
</html>