Misc code cleanups and comment.
[Project_webapp.git] / includes / formregister.php
CommitLineData
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
1f4879b9 12$input_failure = false;
b5f60f89
JB
13
14if (!$form_numstreet) {
a96fefe1 15 echo "The street number is not valid. <br>" ;
1f4879b9 16 $input_failure = true;
b5f60f89
JB
17}
18if (!$form_postalcode) {
a96fefe1 19 echo "The postal code is not valid. <br>";
1f4879b9 20 $input_failure = true;
b5f60f89
JB
21}
22if (!$form_email) {
a96fefe1 23 echo "The email is not valid. <br>";
1f4879b9 24 $input_failure = true;
b5f60f89 25}
a96fefe1
JB
26if (strcmp($form_password, $form_confirmpassword) !== 0) {
27 echo "Password do not match. <br>";
1f4879b9 28 $input_failure = true;
b5f60f89
JB
29}
30
31if (!empty($form_name) && !empty($form_firstname) && !empty($form_numstreet) && !empty($form_street) &&
a96fefe1 32 !empty($form_postalcode) && !empty($form_city) && !empty($form_email) && !empty($form_password) &&
1f4879b9 33 !$input_failure) {
a96fefe1
JB
34 if (!chk_account($form_email)) {
35 global $connection;
36 $hashed_password = password_hash($form_password, PASSWORD_DEFAULT);
37 $sql_pquery = "insert into CLIENTS (NomCl, PrenomCl, EmailCl, PasswordCl, NumRueCl, NomRueCl, CodePosteCl, VilleCl)
38 values (?, ?, ?, ?, ?, ?, ?, ?)";
39 $connection->prepare_query($sql_pquery);
40 $connection->prepared_query_bind_param("ssssisis", array($form_name, $form_firstname, $form_email, $hashed_password, $form_numstreet, $form_street, $form_postalcode, $form_city));
41 $connection->run_prepared_query();
42 $connection->close_prepared_query();
43 echo "You've successfully registered, you will be redirected to the login form in 3 seconds. <br>";
44 redirect("index.php?page=login", 3);
45 } else {
46 echo "You're already registered, you will be redirected to the login form in 3 seconds. <br>";
47 redirect("index.php?page=login", 3);
48 }
49} else {
50 echo "There's a required non filled field or the input in a field do not match the required pattern. <br>";
51 echo "<a href=\"javascript:history.go(-1)\">Retour</a>";
b5f60f89
JB
52}
53?>