-
Notifications
You must be signed in to change notification settings - Fork 0
/
addClasseTreatment.php
62 lines (57 loc) · 1.83 KB
/
addClasseTreatment.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
<?php
require_once("connection.php");
function verifyFields2($field)
{
// $fieldInput = $_POST[$field];
$classe = filter_input(INPUT_POST, "classe");
$debut = filter_input(INPUT_POST, "debut");
$fin = filter_input(INPUT_POST, "fin");
$msgReturn = "";
switch ($field) {
case "classe":
if (strlen($classe) < 5) {
$msgReturn .= "Please add a valid classe name, 5 letters minimum<br>";
}
break;
case "debut":
if ($debut == "") {
$msgReturn .= "Please enter a start date<br>";
}
break;
case "fin":
if ($fin == "") {
$msgReturn .= "Please enter a end date<br>";
}
break;
}
return $msgReturn;
}
function checkError($post)
{
$Error = [];
foreach ($post as $key => $value) {
$err = verifyFields2($key);
if (strlen($err) > 0)
$Error[] = $err;
}
return $Error;
}
if (isset($_POST["classe"], $_POST["debut"], $_POST["fin"])) {
$errors = checkError($_POST);
if (empty($errors)) {
$classe = filter_input(INPUT_POST, "classe");
$debut = filter_input(INPUT_POST, "debut");
$fin = filter_input(INPUT_POST, "fin");
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 = "INSERT INTO `classes`(`id`, `classe`, `debut_cours`, `fin_cours`) VALUES (NULL,'" . $classe . "','" . $debut . "','" . $fin . "')";
$add = $conn->prepare($sql);
$add->execute();
header('Location: addClasse.php?id=database_updated');
}
mysqli_close($conn);
}
}