-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateUser.php
46 lines (40 loc) · 1.01 KB
/
updateUser.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
<?php
include 'functions.php';
// In this file we will update the values in the database.
if(!empty($_POST["uid"]))
{
$uid = $_POST['uid'];
updateValue("Name", $_POST["name"], $uid);
updateValue("UserID", $_POST["username"], $uid);
updateValue("Access", $_POST["Access"], $uid);
updateValue("Phone", $_POST["Phone"], $uid);
if($_POST["Access"] == "Deactive")
{
updateValue("Active", "0", $uid);
}
else
{
updateValue("Active", "1", $uid);
}
}
// Redirect to users.php
header( 'Location: ./users.php' ) ;
// Updates a single value.
function updateValue($valueName, $newValue, $valueID)
{
// Prevents writting an empty value to the table.
if(empty($valueName) OR empty($newValue) OR empty($valueID))
return;
$conn = connectTODB();
$sql = "UPDATE Users SET ".$valueName."='".$newValue."' WHERE UID=".$valueID;
if ($conn->query($sql) === TRUE)
{
echo $valueName."updated successfully";
}
else
{
echo "Error updating record: " . $conn->error . "<br>";
}
$conn->close();
}
?>