-
Notifications
You must be signed in to change notification settings - Fork 0
/
addinv.php
107 lines (94 loc) · 3.61 KB
/
addinv.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
<?php
ini_set('display_errors', 'On');
header('Content-Type: text/html');
include "storedInfo.php"; //contains hostname/username/password/databasename
include "globalConstants.php";
include "sqloperationfunctions.php";
function exit_in_error($stmt){
$msg = $stmt->error;
$stmt->close();
fishy($msg,'inventory');
}
foreach ($_POST as $key => $value) {
if($value=='') fishy("$key must be set",'inventory');
}
if (!in_array($_POST['table'], $itemtables)) {
fishy("how did you ask to add to:{$_POST['table']}",'inventory');
}
$table = $_POST['table'];
if($table=='deck'){
if(isset($_POST['fkid'])){
//duplicate item
$instmt=$mysqli->prepare("INSERT INTO sk8_deck_inv (fk_deck_id, color) VALUES(?,?)");
$instmt->bind_param('is',$_POST['fkid'],$_POST['color']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
} else {
//is new item, will need to be added
$instmt=$mysqli->prepare("INSERT INTO sk8_deck_type (deck_name,length, description, fk_brand_id) VALUES(?,?,?,?)");
$instmt->bind_param('sisi',$_POST['name'],$_POST['length'],$_POST['description'],$_POST['brand_id']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
//after adding item add instance use last id
$last_id = $mysqli->insert_id;
$instmt=$mysqli->prepare("INSERT INTO sk8_deck_inv (fk_deck_id, color) VALUES(?,?)");
$instmt->bind_param('is',$last_id,$_POST['color']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
}
redirect('item added to inventory','inventory');
}
if($table=='truck'){
if(isset($_POST['fkid'])){
//duplicate item
$instmt=$mysqli->prepare("INSERT INTO sk8_truck_inv (fk_truck_id) VALUES(?)");
$instmt->bind_param('i',$_POST['fkid']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
} else {
//is new item, will need to be added
$instmt=$mysqli->prepare("INSERT INTO sk8_truck_type (truck_name, width, fk_brand_id) VALUES(?,?,?)");
$instmt->bind_param('sii',$_POST['name'],$_POST['width'],$_POST['brand_id']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
//after adding item add instance use last id
$last_id = $mysqli->insert_id;
$instmt=$mysqli->prepare("INSERT INTO sk8_truck_inv (fk_truck_id) VALUES(?)");
$instmt->bind_param('i',$last_id);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
}
redirect('item added to inventory','inventory');
}
if($table=='wheel'){
if(isset($_POST['fkid'])){
//duplicate item
$instmt=$mysqli->prepare("INSERT INTO sk8_wheel_inv (fk_wheel_id, color) VALUES(?,?)");
$instmt->bind_param('is',$_POST['fkid'],$_POST['color']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
} else {
//is new item, will need to be added
$instmt=$mysqli->prepare("INSERT INTO sk8_wheel_type (wheel_name,diameter, durometer, fk_brand_id) VALUES(?,?,?,?)");
$instmt->bind_param('siii',$_POST['name'],$_POST['diameter'],$_POST['durometer'],$_POST['brand_id']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
//after adding item add instance use last id
$last_id = $mysqli->insert_id;
$instmt=$mysqli->prepare("INSERT INTO sk8_wheel_inv (fk_wheel_id, color) VALUES(?,?)");
$instmt->bind_param('is',$last_id,$_POST['color']);
$instmt->execute();
if($instmt->errno) exit_in_error($instmt);
$instmt->close();
}
redirect('item added to inventory','inventory');
}
?>