-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtakepayment.php
85 lines (62 loc) · 2.29 KB
/
takepayment.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
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<?php include "config.php"?>
<html>
<head>
<title>Take Payment</title>
<link rel="stylesheet" type="text/css" href="flatly.css">
</head>
<body>
<?php
include "config.php";
function update($mysqli, $drugname, $needQty){
$select = "SELECT qty FROM medicine WHERE drugname = '$drugname'";
$result = $mysqli -> query($select);
while($row = $result->fetch_assoc()) {
if($row["qty"]> $needQty){
$left = $row["qty"]- $needQty;
$update = "UPDATE medicine SET qty = '$left' WHERE drugname = '$drugname'" ;
if(!mysqli_query($mysqli, $update)){
echo "Not updated";
}else{
}
}
}
}
if(isset($_POST['submit'])){
$today = $_POST['today'];
$exp = $_POST['exp'];
if($_POST['today']> $_POST['exp']){
echo "card expired";
}else{
$username = $_POST['username'];
$presid = $_POST['presid'];
$total = $_POST['amount'];
$checkQuery = "SELECT * FROM loginuser where username = '$username'";
$run = mysqli_query($mysqli,$checkQuery);
if(mysqli_num_rows($run)){
$sql = "SELECT Medicines, Quantity, Frequency, Consumption_period FROM prescriptiondata WHERE prescriptionid = '$presid'";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$drugname = $row["Medicines"];
$needQty = $row["Quantity"]*$row["Frequency"]*$row["Consumption_period"];
update($mysqli, $drugname, $needQty);
}
}
$sql = "INSERT INTO incometable(date, username, total) VALUES ('$today', '$username', '$total')";
if ($mysqli->query($sql) === TRUE) {
echo "<div class='alert alert-dismissible alert-primary'>
<button type='button' class='close' data-dismiss='alert'>×</button>
<strong></strong> <a href='issue.php' class='alert-link'>Submit another</a> Payment submitted successfully.
</div>";
} else {
echo "Error: " . $sql . "<br>" . $mysqli->error;
}}
else{
echo "<a href='issue.php' class='alert-link'>Submit another</a>";
}
}
}
?>
</body>
</html>