-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddUser.php
More file actions
61 lines (47 loc) · 1.45 KB
/
addUser.php
File metadata and controls
61 lines (47 loc) · 1.45 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
<?php
if(!empty($_POST['add'])) {
$xml = new DomDocument("1.0","UTF-8");
$xml->load('userDataBase.xml');
$xpath = new DOMXPATH($xml);
foreach ($xpath->query("//idNumber") as $target) {
$idNumTag = $target->nodeValue;
echo $target->nodeValue;
$target->nodeValue = $idNumTag+1;
}
$xml->formatoutput = true;
$xml->save('userDataBase.xml');
$firstName = $_POST["firstName"];
$lastName = $_POST["lastName"];
$ID = $idNumTag+1;
$email = $_POST["email"];
$password = $_POST["password"];
$admin = $_POST["admin"];
if($admin == null){
$admin = "false";
} else $admin = "true";
$rootTag = $xml->getElementsByTagName("root")->item(0);
$userTag = $xml->createElement("user");
$firstNameTag = $xml->createElement("firstName", $firstName);
$lastNameTag = $xml->createElement("lastName", $lastName);
$IDTag = $xml->createElement("ID", $ID);
$emailTag = $xml->createElement("email", $email);
$passwordTag = $xml->createElement("password", $password);
$adminTag = $xml->createElement("admin", $admin);
$userTag->appendChild($firstNameTag);
$userTag->appendChild($lastNameTag);
$userTag->appendChild($IDTag);
$userTag->appendChild($emailTag);
$userTag->appendChild($passwordTag);
$userTag->appendChild($adminTag);
$rootTag->appendChild($userTag);
$xml->save('userDataBase.xml');
}
?>
<script>
var jsvar = "";
<?php
echo "jsvar = '$ID';";
?>
alert("User with id "+jsvar+" has been created.");
window.location.href = "index.php";
</script>