-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_page.php
73 lines (55 loc) · 1.87 KB
/
update_page.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
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
73
<?php include('header.php'); ?>
<?php include('dbcon.php'); ?>
<?php
//Fetching previous saved data into textboxes
if(isset($_GET['id']))
{
$id = $_GET['id'];
$query = "SELECT * FROM stock WHERE Id = $id";
$result = mysqli_query($connection, $query);
if(!$result) {
die("Query failed");
}
else
{
$row = mysqli_fetch_assoc($result);
// print_r($row);
}
}
?>
<?php
//Updating changes to database
if(isset($_POST['update_stock']))
{
if(isset($_GET['id_new'])){
$idnew = $_GET['id_new'];
}
$pname = $_POST['pname'];
$qty = $_POST['qty'];
$price = $_POST['price'];
$query = "UPDATE stock SET Product_name = '$pname', Quantity = '$qty', Price = '$price' WHERE Id=$idnew";
$result = mysqli_query($connection, $query);
if(!$result) {
die("Query failed");
}
else {
header('location:index.php?update_message=Product details updated successfully');
}
}
?>
<form Action ="update_page.php?id_new=<?php echo $id; ?>" method = "post">
<div class="form-group">
<label for="pname">Product Name</label>
<input type="text" name="pname" class="form-control" value = <?php echo $row ['Product_name']?> >
</div>
<div class="form-group">
<label for="qty">Quantity</label>
<input type="number" name="qty" class="form-control" value = <?php echo $row['Quantity']?>>
</div>
<div class="form-group">
<label for="price">Price</label>
<input type="number" name="price" class="form-control" value = <?php echo $row['Price']?>>
</div>
<input type="submit" class="btn btn-success" name="update_stock" value ="UPDATE">
</form>
<?php include('footer.php'); ?>