Commit | Line | Data |
---|---|---|
b5f60f89 JB |
1 | <?php |
2 | $form_name = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING); | |
3 | $form_firstname = filter_input(INPUT_POST, "firstname", FILTER_SANITIZE_STRING); | |
4 | $form_numstreet = filter_input(INPUT_POST, "numstreet", FILTER_VALIDATE_INT); | |
5 | $form_street = filter_input(INPUT_POST, "street", FILTER_SANITIZE_STRING); | |
6 | $form_postalcode = filter_input(INPUT_POST, "postalcode", FILTER_VALIDATE_INT); | |
a96fefe1 | 7 | $form_city = filter_input(INPUT_POST, "city", FILTER_SANITIZE_STRING); |
b5f60f89 JB |
8 | $form_email = filter_input(INPUT_POST, "email", FILTER_VALIDATE_EMAIL); |
9 | $form_password = filter_input(INPUT_POST, "password", FILTER_SANITIZE_STRING); | |
10 | $form_confirmpassword = filter_input(INPUT_POST, "confirmpassword", FILTER_SANITIZE_STRING); | |
11 | ||
12 | $error_numstreet = false; | |
13 | $error_postalcode = false; | |
14 | $error_email = false; | |
15 | $error_password = false; | |
16 | ||
17 | if (!$form_numstreet) { | |
a96fefe1 | 18 | echo "The street number is not valid. <br>" ; |
b5f60f89 JB |
19 | $error_numstreet = true; |
20 | } | |
21 | if (!$form_postalcode) { | |
a96fefe1 | 22 | echo "The postal code is not valid. <br>"; |
b5f60f89 JB |
23 | $error_postalcode = true; |
24 | } | |
25 | if (!$form_email) { | |
a96fefe1 | 26 | echo "The email is not valid. <br>"; |
b5f60f89 JB |
27 | $error_email = true; |
28 | } | |
a96fefe1 JB |
29 | if (strcmp($form_password, $form_confirmpassword) !== 0) { |
30 | echo "Password do not match. <br>"; | |
b5f60f89 JB |
31 | $error_password = true; |
32 | } | |
33 | ||
34 | if (!empty($form_name) && !empty($form_firstname) && !empty($form_numstreet) && !empty($form_street) && | |
a96fefe1 JB |
35 | !empty($form_postalcode) && !empty($form_city) && !empty($form_email) && !empty($form_password) && |
36 | !$error_numstreet && !$error_postalcode && !$error_email && !$error_password) { | |
37 | if (!chk_account($form_email)) { | |
38 | global $connection; | |
39 | $hashed_password = password_hash($form_password, PASSWORD_DEFAULT); | |
40 | $sql_pquery = "insert into CLIENTS (NomCl, PrenomCl, EmailCl, PasswordCl, NumRueCl, NomRueCl, CodePosteCl, VilleCl) | |
41 | values (?, ?, ?, ?, ?, ?, ?, ?)"; | |
42 | $connection->prepare_query($sql_pquery); | |
43 | $connection->prepared_query_bind_param("ssssisis", array($form_name, $form_firstname, $form_email, $hashed_password, $form_numstreet, $form_street, $form_postalcode, $form_city)); | |
44 | $connection->run_prepared_query(); | |
45 | $connection->close_prepared_query(); | |
46 | echo "You've successfully registered, you will be redirected to the login form in 3 seconds. <br>"; | |
47 | redirect("index.php?page=login", 3); | |
48 | } else { | |
49 | echo "You're already registered, you will be redirected to the login form in 3 seconds. <br>"; | |
50 | redirect("index.php?page=login", 3); | |
51 | } | |
52 | } else { | |
53 | echo "There's a required non filled field or the input in a field do not match the required pattern. <br>"; | |
54 | echo "<a href=\"javascript:history.go(-1)\">Retour</a>"; | |
b5f60f89 JB |
55 | } |
56 | ?> |