-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifyUserTreatment.php
91 lines (84 loc) · 2.94 KB
/
modifyUserTreatment.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
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
<?php
require_once("connection.php");
$result = $connect->query("SELECT * FROM users");
function verifyFields($field)
{
$nom = filter_input(INPUT_POST, "nom");
$telephone = filter_input(INPUT_POST, "telephone");
$email = filter_input(INPUT_POST, "email");
$password = filter_input(INPUT_POST, "password");
$classe = filter_input(INPUT_POST, "classe");
$role = filter_input(INPUT_POST, "role");
$msgReturn = "";
switch ($field) {
case "classe":
if ($classe == "") {
$msgReturn .= "Please select a class<br>";
}
break;
case "nom":
if ($nom == "") {
$msgReturn .= "Please select the student<br>";
}
break;
case "telephone":
if ($telephone == "") {
$msgReturn .= "Please add a telephone number<br>";
}
break;
case "email":
if ($email == "" && $telephone = "oui") {
$msgReturn .= "Please add email address<br>";
}
break;
case "password":
if ($password == "") {
$msgReturn .= "Please add password<br>";
}
break;
case "role":
if ($role == "") {
$msgReturn .= "Please add role<br>";
}
break;
}
return $msgReturn;
}
function checkError($post)
{
$Error = [];
foreach ($post as $key => $value) {
$err = verifyFields($key);
if (strlen($err) > 0)
$Error[] = $err;
}
return $Error;
}
if (isset($_POST["classe"], $_POST["nom"], $_POST["telephone"], $_POST["email"], $_POST["password"])) {
$errors = checkError($_POST);
if (empty($errors)) {
$id = $_GET['id'];
$nom = filter_input(INPUT_POST, "nom");
$telephone = filter_input(INPUT_POST, "telephone");
$email = filter_input(INPUT_POST, "email");
$password = filter_input(INPUT_POST, "password");
$classe = filter_input(INPUT_POST, "classe");
$role = filter_input(INPUT_POST, "role");
if (!$conn) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
} else {
$sql = $conn->prepare("UPDATE `users` SET `nom`=:nom, `telephone`=:telephone, `email`=:email, `password`=:password, `role`=:role, `classe`=:classe where `id`=:id");
$sql->bindParam(':nom', $nom);
$sql->bindParam(':telephone', $telephone);
$sql->bindParam(':email', $email);
$sql->bindParam(':password', $password);
$sql->bindParam(':role', $role);
$sql->bindParam(':classe', $classe);
$sql->bindParam(':id', $id);
$sql->execute();
header('Location: mainMenu.php?id=Database_updated');
}
}
}