-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertkeg.php
More file actions
151 lines (130 loc) · 4.67 KB
/
Copy pathinsertkeg.php
File metadata and controls
151 lines (130 loc) · 4.67 KB
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
<html>
<head>
<title>Insert Keg</title>
<?php
include "includes/base.php";
?>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<?php include("includes/header.php");?>
<?php //include("includes/nav.php");?>
<div id='section'>
<div class="container">
<br>
<form class='form-horizontal' action="" method="POST">
<fieldset>
<legend>Update Keg Inventory</legend>
<?php
if (isset($_SESSION['error']) || isset($_SESSION['success'])) {
if ($_SESSION['error']) {
echo "<div class='btn btn-danger col-md-4 form-control'>". $_SESSION['error']. "</div>";
echo "<br><br>";
$_SESSION['error'] = '';
}
else if($_SESSION['success']) {
print "<div class='btn btn-success form-control'>". $_SESSION['success']. "</div>";
echo "<br><br>";
$_SESSION['success'] = '';
}
}
?>
<div class="form-group">
<label class="col-md-4 control-label">Keg ID:</label>
<div class="col-md-4">
<input class='form-control input-md' type="text" name="keg_id" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Location:</label>
<div class="col-md-4">
<input class="form-control input-md" type="text" name="location" value="">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Batch ID:</label>
<div class="col-md-4">
<input class="form-control input-md" type="text" name="batch_id" value="">
</div>
</div>
<div class='form-group'>
<label class='col-md-4 control-label'></label>
<div class="col-md-4">
<input class="btn btn-info form-control" type="submit" name="submitnew_keg" value="Submit">
</div>
</div>
</fieldset>
</form>
</div>
<div class="container">
<a href="inventory.php" class="button">Back to Inventory</a><br>
</div>
</div>
<?php include("includes/footer.php");?>
</body>
</html>
<?php
if(isset($_POST['submitnew_keg'])) {
$kegid = htmlspecialchars($_POST['keg_id']);
$location = htmlspecialchars($_POST['location']);
$batchid = htmlspecialchars($_POST['batch_id']);
if($kegid == '' || $location == '' || $batchid == '') {
$_SESSION['error'] = "Error: All fields must be filled.";
header('Refresh:0');
exit();
}
else if(!is_numeric($kegid)) {
$_SESSION['error'] = "Error: Keg ID must be a number.";
header('Refresh:0');
exit();
}
else if(!is_numeric($batchid)){
$_SESSION['error'] = "Error: Batch ID must be a number.";
header('Refresh:0');
exit();
}
$query = "SELECT keg_id FROM keg WHERE keg_id = ". $kegid;
if($stmt = mysqli_prepare($link, $query)){
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 1) {
$_SESSION['error'] = "Error: A keg with that ID already exists. Please update it instead.";
mysqli_stmt_close($stmt);
header('Refresh:0');
exit();
}
mysqli_stmt_close($stmt);
}
$query = "SELECT batch_id FROM batch WHERE batch_id = ". $batchid;
if($stmt = mysqli_prepare($link, $query)){
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if(mysqli_num_rows($result) == 0) {
$_SESSION['error'] = "Error: That Batch ID doesn't exist.";
mysqli_stmt_close($stmt);
header('Refresh:0');
exit();
}
mysqli_stmt_close($stmt);
}
$sql = "INSERT INTO keg (keg_id,location,batch_id) VALUES (?,?,?)";
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt,"sss",$kegid,$location,$batchid);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
$_SESSION['success'] = "Success: Keg has been added.";
//require "insertingredient.php";
header('Refresh:0');
exit();
}
else {
$_SESSION['error'] = "Error: Keg not successfully added.";
//require "insertingredient.php";
header('Refresh:0');
exit();
}
}
?>
<?php
mysqli_close($link);
?>