forked from hewagekasunthilina/Pharmacy-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validateorder.php
77 lines (53 loc) · 1.89 KB
/
validateorder.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
74
75
76
77
<?php
session_start();
$mysqli = new mysqli('localhost', 'root', '', 'Supplier') or die(mysqli_error($mysqli));
$id = 0;
$update = false;
$orderid = '';
$supplierid = '';
$medname = '';
$qty = '';
$date = '';
if(isset($_POST['ORDER'])){
$orderid = $_POST['orderid'];
$supplierid = $_POST['supplierid'];
$medname = $_POST['medname'];
$qty = $_POST['qty'];
$date = $_POST['date'];
$mysqli->query("INSERT INTO orders (orderid, supplierid, medName, qty, date) VALUES('$orderid', '$supplierid', '$medname', '$qty', '$date')") or die($mysqli->error);
$_SESSION['message'] = "Record has been saved!";
$_SESSION['msg_type'] = "success";
header("location: Orders.php");
}
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$mysqli->query("DELETE from orders WHERE id=$id") or die($mysqli->error());
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: Orders.php");
}
if (isset($_GET['edit'])){
$id = $_GET['edit'];
$update = true;
$result = $mysqli->query("SELECT * FROM orders WHERE id = $id") or die($mysqli->error());
if (count($result)==1){
$row = $result->fetch_array();
$orderid = $row['orderid'];
$supplierid = $row['supplierid'];
$medname = $row['medName'];
$qty = $row['qty'];
$date = $row['date'];
}
}
if (isset($_POST['UPDATE'])){
$id = $_POST['id'];
$orderid = $_POST['orderid'];
$supplierid = $_POST['supplierid'];
$medname = $_POST['medname'];
$qty = $_POST['qty'];
$date = $_POST['date'];
$mysqli->query("UPDATE orders SET orderid='$orderid', supplierid ='$supplierid', medName= '$medname', qty='$qty', date='$date' WHERE id=$id") or die($mysqli->error);
$_SESSION['message'] = "Record has been UPDATED!";
$_SESSION['msg_type'] = "warning";
header("location: Orders.php");
}