-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformProcess.php
More file actions
149 lines (141 loc) · 6.1 KB
/
formProcess.php
File metadata and controls
149 lines (141 loc) · 6.1 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
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Other form process page</title>
</head>
<body>
<?php
// Start of form processing for keyboard page
// Variable list and require list
require 'wLInventory.php';
require $SQLOperationFile;
require $errorFunctionsFile;
// Start of main program
// Insert form
$form = $_POST['form'];
switch($form){
case 'form1':
$insertOP = new insertOp(); // Class object for inserting data
$columnValues = [];
$columnNames = [];
$count = 0;
// Start of assigning variables to POST values
foreach($_POST as $post => $values){
if($post != "form" && $post != "tableSelect" && !empty($values)){
$columnValues[$count] = validate_input($values, $post);
if($post == "cost"){
if (!is_numeric($columnValues[$count])) {
++$errorCount;
echo "The value for cost is not numeric. Error count: \"$errorCount\"<br>";
$columnValues[$count] = null;
}
else {
$columnValues[$count] = (float)$columnValues[$count];
}
}
if($post != "p_id"){// change this value if the primary ID tags are different.
$columnNames[$count] = $post;
}
$count++;
}
}
$table_name = validate_input($_POST['tableSelect'], "Table name");
// End of assigning variable to POST values
if($errorCount == 0) {
$idName = find_ID($table_name);//goes to wLInventory.php
$insertOP -> connect();
$insertOP -> set_table_names($idName, ...$columnNames);// goes to SQLOp.php
$statement = $insertOP -> add_query($table_name, ...$columnValues);// goes to SQLOp.php
$insertOP -> execute_query($statement);// goes to SQLOp.php
//header("Location: inventoryForm.html");
// exit();
}
else{
echo "No form data received";
}
break;
// View Table form ***********************************************************************
case 'form2':
$viewOp = new queryOp(); // Instantiating queryOp class for viewing data
$table_name = validate_input($_POST['tableView'], $description_k[6]);
if($errorCount == 0) {
$viewOp -> connect();
/**
* Sets the table name and queries the table.
*
* @param string $table_name Name of the table.
*/
$viewOp -> set_table_name($table_name);
$viewOp -> query_table();
$viewOp -> print_table();
$viewOp -> DB_close();
}
else{
echo "No form data received";
}
break;
// Operation to update table row ***************************************************************************
case 'form3':
// Local variables
$updateOp = new updateOp(); // Class object for updating data
$tableNameValues =[];
// grabbing the table name
$table_name = validate_input($_POST['tableUpdate'], "update table row");
try{// grabbing the primary ID value
if(!empty($_POST['pValue'])){
$p_id_value = validate_input($_POST['pValue'],"Need p_id value for $table_name");
}
else{
throw new Exception ("Need a Primary ID to update a row on a table.");
}
}
catch(Exception $e){
echo "Error:" . $e -> getMessage();
}
foreach($_POST as $post => $value){
if($post != "form" && $post != "tableUpdate" && $post != "pValue" && !empty($value)){
$tableNameValues[$post] = validate_input($value, $post);
}
}
if($errorCount == 0) {
$updateOp -> connect();
if(!empty($tableNameValues)){
/**
* Sets the table update values.
*
* @param string $table_name Name of the table.
* @param array $tableNameValues Array of columns and values to update.
* @param int $p_id_value Primary ID value.
*/
$updateOp -> set_table_update($table_name, $tableNameValues, $p_id_value);}
else{
echo "No values to update";
}
$updateOp -> update_table();
$updateOp -> DB_close();
}
break;
// Operation to delete table row ***********************************************************************
case 'form4':
$deleteOp = new deleteOp(); // Instantiating deleteOp class for deleting data
$table_name = validate_input($_POST['tableDelete'], "deleting row for keyboard table");
$p_id = validate_input($_POST['pValue'], $description_k[0]);
if($errorCount == 0) {
$deleteOp -> connect();
/**
* Sets the table delete values.
*
* @param string $table_name Name of the table.
* @param int $p_id Primary ID value.
*/
$deleteOp -> set_table_delete($table_name, $p_id);
$deleteOp -> delete_row();
$deleteOp -> DB_close();
}
break;
}
?>
</body>
</html>