forked from hewagekasunthilina/Pharmacy-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StockItem_process.php
69 lines (52 loc) · 1.86 KB
/
StockItem_process.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
<?php
session_start();
$mysqli = new mysqli('localhost', 'root', '', 'nimedco') or die(mysqli_error($mysqli));
$id = 0;
$update = false;
$ItemID = '';
$ItemName ='';
$Description ='';
$Category ='';
$Price ='';
if(isset($_POST['save'])){
$ItemID = $_POST['ItemID'];
$ItemName = $_POST['ItemName'];
$Description = $_POST['Description'];
$Category = $_POST['Category'];
$Price = $_POST['Price'];
$mysqli->query("INSERT INTO stockitem(ItemID, ItemName, Description, Category, Price) VALUES('$ItemID', '$ItemName', '$Description', '$Category', '$Price')") or die($mysqli->error);
$_SESSION['message'] = "Record has been saved!";
$_SESSION['msg_type'] = "success";
header("location: StockItem.php");
}
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$mysqli->query("DELETE FROM stockitem WHERE id=$id") or die($mysql->error());
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: StockItem.php");
}
if (isset($_GET['edit'])){
$id = $_GET['edit'];
$update = true;
$result = $mysqli->query("SELECT * FROM stockitem WHERE id=$id") or die($mysqli->error());
$row = $result->fetch_array();
$ItemID = $row['ItemID'];
$ItemName = $row['ItemName'];
$Description = $row['Description'];
$Category = $row['Category'];
$Price = $row['Price'];
}
if(isset($_POST['update'])){
$id = $_POST['id'];
$ItemID = $_POST['ItemID'];
$ItemName = $_POST['ItemName'];
$Description = $_POST['Description'];
$Category = $_POST['Category'];
$Price = $_POST['Price'];
$mysqli->query("UPDATE stockitem SET ItemID='$ItemID', ItemName='$ItemName', Description='$Description', Category='$Category', Price='$Price' WHERE id=$id") or die($mysqli->error);
$_SESSION['message'] = "Record has been updateed!";
$_SESSION['msg_type'] = "warning";
header('location: StockItem.php');
}
?>