-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.php
More file actions
42 lines (30 loc) · 986 Bytes
/
save.php
File metadata and controls
42 lines (30 loc) · 986 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
function has($tocheck) {
foreach($_GET as $key => $value) {
if($key == $tocheck) {
return true;
}
}
return false;
}
if(has('income')) {
$xmlFile = new DOMDocument();
$xmlFile->load('./data.xml');
$xmlFile->documentElement->getElementsByTagName('income')->item(0)->nodeValue = $_GET['income'];
$xmlFile->save('./data.xml');
}
else if(has('amount') && has('desc')){
$xmlFile = new DOMDocument();
$xmlFile->load('./data.xml');
$element = $xmlFile->createElement('expense');
$amount = $_GET['amount'];
$desc = $_GET['desc'];
$child1 = $xmlFile->createElement('amount', $amount);
$child2 = $xmlFile->createElement('desc', $desc);
$element->appendChild($child1);
$element->appendChild($child2);
$xmlFile->getElementsByTagName('expenses')->item(0)->appendChild($element);
$xmlFile->save('./data.xml');
}
echo '<script> window.location.href = "./index.html";</script>';
?>