-
Notifications
You must be signed in to change notification settings - Fork 14
/
update.php
191 lines (169 loc) · 8.07 KB
/
update.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
// Include config file
require_once "config.php";
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
$stock_id="";
$drug_name="";
$date_supplied="";
$description="";
$supplier="";
$quantity="";
$cost="";
$availability="";
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>insertion/deletion of stock</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div id="main-wrapper">
<center><h2>INSERT/UPDATE/DELETE STOCK!</h2></center>
<div class="inner_container">
<?php
if(isset($_POST['fetch_btn'])){
$stock_id = $_POST['stock_id'];
if($stock_id=="")
{
echo '<script type="text/javascript">alert("enetr stockid to get drug details")</script>';
}
{
$query="select * from stock where stock_id=$stock_id";
$query_run=mysqli_query($link,$query);
if($query_run)
{
if(mysqli_num_rows($query_run)>0)
{
$row= mysqli_fetch_array($query_run,MYSQLI_ASSOC);
$stock_id=$row['stock_id'];
$drug_name=$row['drug_name'];
$date_supplied=$row['date_supplied'];
$description=$row['description'];
$supplier=$row['supplier'];
$quantity=$row['quantity'];
$cost=$row['cost'];
$availability=$row['availability'];
}
else{
echo '<script type="text/javascript">alert("invalid stock id")</script>';
}
}
else{
echo '<script type="text/javascript">alert("error in query")</script>';
}
}
}
?>
<form action="update.php" method="post">
<label><b>Stock ID</b> </label><button id="btn_go" name="fetch_btn" type="submit">GO</button>
<input type="text" placeholder="enter the stock id" name="stock_id" value="<?php echo $stock_id; ?>">
<label><b>Drug Name</b></label>
<input type="text" placeholder="enter the drug name" name="drug_name" value="<?php echo $drug_name; ?>">
<label><b>Date Supplied</b></label>
<input type="date" placeholder="enter date supplied" name="date_supplied" value="<?php echo $date_supplied; ?>">
<label><b>Description</b></label>
<input type="text" placeholder="enter the Description" name="description" value="<?php echo $description; ?>">
<label><b>Supplier</b></label>
<input type="text" placeholder="enter the supplier" name="supplier" value="<?php echo $supplier; ?>">
<label><b>Quantity</b></label>
<input type="number" placeholder="enter the quantity" name="quantity" value="<?php echo $quantity; ?>">
<label><b>Cost</b></label>
<input type="number" placeholder="enter the cost" name="cost" value="<?php echo $cost; ?>">
<label><b>Availability</b></label>
<input type="text" placeholder="enter availability" name="availability" value="<?php echo $availability; ?>">
<center>
<button id="btn_insert" name="insert_btn" type="submit">Insert</button>
<button id="btn_update" name="update_btn" type="submit">Update</button>
<button id="btn_delete" name="delete_btn" type="submit">Delete</button>
<p>
<a href="stock.php" class="btn btn-danger">GO BACK</a>
</p>
</center>
</form>
<?php
if(isset($_POST['insert_btn'])){
$stock_id=$_POST['stock_id'];
$drug_name=$_POST['drug_name'];
$date_supplied=$_POST['date_supplied'];
$description=$_POST['description'];
$supplier=$_POST['supplier'];
$quantity=$_POST['quantity'];
$cost=$_POST['cost'];
$availability=$_POST['availability'];
if($stock_id=="" || $drug_name=="" || $date_supplied=="" || $description=="" || $supplier=="" || $quantity=="" || $cost==""|| $availability=="")
{
echo '<script type="text/javascript">alert("insert values in all fields")</script>';
}
else{
$query = "insert into stock values($stock_id,'$drug_name','$date_supplied','$description', '$supplier',$quantity,$cost,'$availability')";
$query_run=mysqli_query($link,$query);
if($query_run)
{
echo '<script type="text/javascript">alert("values intered successfully:)")</script>';
}
else{
echo '<script type="text/javascript">alert("values intered successfully:)")</script>';
}
}
}
else if(isset($_POST['update_btn']))
{
if($_POST['stock_id']=="" || $_POST['drug_name']=="" || $_POST['date_supplied']=="" || $_POST['description']=="" || $_POST['supplier']=="" || $_POST['quantity']=="" || $_POST['cost']=="" || $_POST['availability']=="")
{
echo '<script type="text/javascript">alert("insert values in all fields")</script>';
}
else{
$stock_id=$_POST['stock_id'];
$drug_name=$_POST['drug_name'];
$date_supplied=$_POST['date_supplied'];
$description=$_POST['description'];
$supplier=$_POST['supplier'];
$quantity=$_POST['quantity'];
$cost=$_POST['cost'];
$availability=$_POST['availability'];
$query = "update stock
SET stock_id='$stock_id', drug_name='$drug_name', date_supplied='$date_supplied', description='$description', supplier='$supplier', quantity='$quantity', cost='$cost', availability='$availability'
WHERE stock_id=$stock_id";
$query_run = mysqli_query($link,$query);
if($query_run)
{
echo '<script type="text/javascript">alert("stock updated successfully:)")</script>';
}
else{
echo '<script type="text/javascript">alert("error")</script>';
}
}
}
else if(isset($_POST['delete_btn']))
{
if($_POST['stock_id']=="")
{
echo '<script type="text/javascript">alert("enter stock id to delete")</script>';
}
else{
$stock_id = $_POST['stock_id'];
$query = "delete from stock
WHERE stock_id=$stock_id";
$query_run = mysqli_query($link,$query);
if($query_run)
{
echo '<script type="text/javascript">alert("product deleted:)")</script>';
}
else{
echo '<script type="text/javascript">alert("error")</script>';
}
}
}
?>
</div>
</div>
</body>
</html>