-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_prod.php
More file actions
26 lines (25 loc) · 894 Bytes
/
delete_prod.php
File metadata and controls
26 lines (25 loc) · 894 Bytes
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
<!--DELETE FUNCTION-->
<?php
if (($_SERVER["REQUEST_METHOD"] == "POST")) {
//load contents of database
$string_data = file_get_contents("products.php");
//unserialize contents
$products = unserialize($string_data);
//isolate associative array from POST
foreach ($_POST as $key => $val) {
$array = $val;
}
//isolate key
foreach ($array as $key => $val) {
$name = $key;
}
//search key within database (i.e. name)
$key = 1 + array_search($key, array_column($products, 'name'));
//remove the item from the array
unset($products[$key]);
//write contents of array back into database
file_put_contents("products.php", serialize($products));
header("Location: inventory.php");
}
?>
<!--END DELETE FUNC-->