-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateinfo.php
154 lines (149 loc) · 7.92 KB
/
updateinfo.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
session_start();
if (!isset($_SESSION["user"])) {
header("Location: connexion.php");
exit;
}
echo "<pre>";
var_dump($_SESSION);
echo "</pre>";
if(isset($_POST["prenom"], $_POST["nom"], $_POST["height"], $_POST["weight"]) && !empty($_POST["prenom"]) && !empty($_POST["nom"]) && !empty($_POST["height"]) && !empty($_POST["weight"])) {
$_SESSION["error"] = [];
$lastname = strip_tags($_POST["nom"]);
$name = strip_tags($_POST["prenom"]);
$height = strip_tags($_POST["height"]);
$height = (is_numeric($height)) ? (int)$height : 0; // Fais passer en integer
$weight = strip_tags($_POST["weight"]);
$weight = (is_numeric($weight)) ? (int)$weight : 0;
$sporthebdo = strip_tags($_POST["sporthebdo"]);
$sporthebdo = (is_numeric($sporthebdo)) ? (int)$sporthebdo : 0;
if(strlen($name) < 2) {
$_SESSION["error"][] = "Le prénom doit conteir plus d'un caractère.";
}
if(strlen($lastname) < 2) {
$_SESSION["error"][] = "Le nom doit contenir plus d'un caractère.";
}
if ($height < 100 || $height > 220) {
$_SESSION["error"][] = "Erreur lors de la saisie de la taille, la taille doit être comprise entre 100cm et 220cm.";
}
if ($weight < 30 || $weight > 200) {
$_SESSION["error"][] = "Erreur lors de la saisie du poids, le poids doit être compris entre 30 et 200kg.";
}
// Ici les données de bases sont bonnes
require_once "includes/function.php";
if(!validateDate($_POST["birthday"], 'Y-m-d')){
$_SESSION["error"][] = "Erreur lors de la saisie de la date.";
}
if($sporthebdo < 0 && $sporthebdo > 40) {
$_SESSION["error"][] = "Erreur lors de la saisie du nombre d'heure par semaine.";
}
if(!empty($_POST["phonetel"]) && !preg_match("#[0][6][- \.?]?([0-9][0-9][- \.?]?){4}$#", $_POST["phonetel"])){
$_SESSION["error"][] = "Erreur lors de la saisie du numéro de téléphone.";
}
// Ici toutes les données sont "utlisables"
if($_SESSION["error"] === []) {
if(!empty($_POST["birthday"]) && isset($_POST["birthday"]) && $_POST["birthday"]!=="1990-01-01") {
$birthday = $_POST["birthday"];
}
if(!empty($_POST["phonetel"]) && preg_match("#[0][6][- \.?]?([0-9][0-9][- \.?]?){4}$#", $_POST["phonetel"])){
$tel = $_POST["phonetel"];
}
require "includes/connect.php";
if(isset($birthday, $tel)){
$sql = "UPDATE `membres` SET `nom` = :nom, `prenom` = :prenom, `taille` = :taille, `poids` = :poids, `tel` = :tel, `sport` = :sport, `anniv` = :anniv WHERE id = :id";
$query = $db->prepare($sql);
$query->bindValue(":nom", $lastname, PDO::PARAM_STR);
$query->bindValue(":prenom", $name, PDO::PARAM_STR);
$query->bindValue(":taille", $height, PDO::PARAM_STR);
$query->bindValue(":poids", $weight, PDO::PARAM_STR);
$query->bindValue(":tel", $tel, PDO::PARAM_STR);
$query->bindValue(":sport", $sporthebdo, PDO::PARAM_STR);
$query->bindValue(":anniv", $birthday, PDO::PARAM_STR);
$query->bindValue(":id", $_SESSION["user"]["id"], PDO::PARAM_STR);
$query->execute();
$_SESSION["validinsertcalorie"] = ["Vos informations ont bien été validé ! 🥳"];
// $_SESSION["user"] = [
// "id" => $_SESSION["user"]["id"],
// "name" => $name,
// "lastname" => $lastname,
// "email" => $_SESSION["user"]["email"],
// "height" => $height,
// "weight" => $weight,
// "sex" => $_SESSION["user"]["sex"],
// "tel" => $tel,
// "sport" => $sporthebdo,
// "anniv" => $birthday
// ];
}
if(isset($birthday) && !isset($tel)) {
$sql = "UPDATE `membres` SET `nom` = :nom, `prenom` = :prenom, `taille` = :taille, `poids` = :poids, `sport` = :sport, `anniv`= :anniv WHERE id = :id";
$query = $db->prepare($sql);
$query->bindValue(":nom", $lastname, PDO::PARAM_STR);
$query->bindValue(":prenom", $name, PDO::PARAM_STR);
$query->bindValue(":taille", $height, PDO::PARAM_STR);
$query->bindValue(":poids", $weight, PDO::PARAM_STR);
$query->bindValue(":sport", $sporthebdo, PDO::PARAM_STR);
$query->bindValue(":anniv", $birthday, PDO::PARAM_STR);
$query->bindValue(":id", $_SESSION["user"]["id"], PDO::PARAM_STR);
$query->execute();
$_SESSION["validinsertcalorie"] = ["Vos informations ont bien été validé ! 🥳"];
// $_SESSION["user"] = [
// "id" => $_SESSION["user"]["id"],
// "name" => $name,
// "lastname" => $lastname,
// "email" => $_SESSION["user"]["email"],
// "height" => $height,
// "weight" => $weight,
// "sex" => $_SESSION["user"]["sex"],
// "tel" => $tel,
// "sport" => $sporthebdo,
// "anniv" => $birthday
// ];
}
if(!isset($birthday) && isset($tel)) {
$sql = "UPDATE `membres` SET `nom` = :nom, `prenom` = :prenom, `taille` = :taille, `poids` = :poids, `tel` = :tel,`sport` = :sport WHERE id = :id";
$query = $db->prepare($sql);
$query->bindValue(":nom", $lastname, PDO::PARAM_STR);
$query->bindValue(":prenom", $name, PDO::PARAM_STR);
$query->bindValue(":taille", $height, PDO::PARAM_STR);
$query->bindValue(":poids", $weight, PDO::PARAM_STR);
$query->bindValue(":tel", $tel, PDO::PARAM_STR);
$query->bindValue(":sport", $sporthebdo, PDO::PARAM_STR);
$query->bindValue(":id", $_SESSION["user"]["id"], PDO::PARAM_STR);
$query->execute();
$_SESSION["validinsertcalorie"] = ["Vos informations ont bien été validé ! 🥳"];
}
if(!isset($birthday) && !isset($tel)) {
$sql = "UPDATE `membres` SET `nom` = :nom, `prenom` = :prenom, `taille` = :taille, `poids` = :poids, `sport` = :sport WHERE id = :id";
$query = $db->prepare($sql);
$query->bindValue(":nom", $lastname, PDO::PARAM_STR);
$query->bindValue(":prenom", $name, PDO::PARAM_STR);
$query->bindValue(":taille", $height, PDO::PARAM_STR);
$query->bindValue(":poids", $weight, PDO::PARAM_STR);
$query->bindValue(":sport", $sporthebdo, PDO::PARAM_STR);
$query->bindValue(":id", $_SESSION["user"]["id"], PDO::PARAM_STR);
$query->execute();
$_SESSION["validinsertcalorie"] = ["Vos informations ont bien été validé ! 🥳"];
}
$_SESSION["user"] = [
"id" => $_SESSION["user"]["id"],
"name" => $name,
"lastname" => $lastname,
"email" => $_SESSION["user"]["email"],
"height" => $height,
"weight" => $weight,
"sex" => $_SESSION["user"]["sex"],
"tel" => $tel,
"sport" => $sporthebdo,
"anniv" => $birthday
];
header("Location: index.php");
} else {
header("Location: index.php");
}
// echo $birthday;
} else {
$_SESSION["error"] = ["Une erreur est survenue."];
header("Location: index.php");
}
?>