From 0e82d768d514dcafc05ebadd84c2382de20ba64d Mon Sep 17 00:00:00 2001 From: Samuel ORTION Date: Thu, 10 Jun 2021 21:02:55 +0200 Subject: [PATCH] Added join (adhesion) form --- public/join/index.php | 59 ++++++++++++++++++++++++++++++ public/join/join.php | 85 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 public/join/index.php create mode 100644 public/join/join.php diff --git a/public/join/index.php b/public/join/index.php new file mode 100644 index 0000000..3caa4c0 --- /dev/null +++ b/public/join/index.php @@ -0,0 +1,59 @@ + + + + + + + + Les Cocottes Minutes + + + + + +
+ + +
+
+
+
+

Adhérer aux Cocottes Minutes

+
+ + + + + + + +
+

* obligatoire

+ +
+ +
+ +
+
+
+ + + + + + + \ No newline at end of file diff --git a/public/join/join.php b/public/join/join.php new file mode 100644 index 0000000..6869d30 --- /dev/null +++ b/public/join/join.php @@ -0,0 +1,85 @@ + PDO::ERRMODE_EXCEPTION + )); + }catch (Exception $e){ + die("Error : ".$e->getMessage()); + } + // Check if table exitst + $req = $db->prepare('CREATE TABLE IF NOT EXISTS members (id SERIAL PRIMARY KEY, name varchar(125) NOT NULL UNIQUE, student_number varchar(8) UNIQUE, email varchar(125) UNIQUE)'); + $req->execute(); + if (strlen($name) > 125) + { + $_SESSION['error_msg'] .= "Le nom entré est trop long.\n"; + } + if (strlen($email) > 125) + { + $_SESSION['error_msg'] .= "L'email entré est trop long.\n"; + } + if (strlen($number) > 8) + { + $_SESSION['error_msg'] .= "Votre numéro d'étudiant semble incorrect (il comporte plus de 8 caractères.\n"; + } + if ($_SESSION['error_msg'] == "") + { + try { + $req = $db->prepare('INSERT INTO members (name, student_number, email) VALUES (?, ?, ?)'); + $req->execute(array($name, $number, $email)); + } catch (Exception $e) { + $_SESSION['error_msg'] .= $e->getMessage(); + } + } +} + +$_SESSION['error_msg'] = ""; +if (isset($_POST['submit'])) +{ + if (isset($_POST['name']) and $_POST['name'] != "") + { + $name = $_POST['name']; + $_SESSION['name'] = $name; + } else + { + $_SESSION['error_msg'] .= "Vous n'avez pas entré de nom.\n"; + } + if (isset($_POST['number'])) + { + $number = $_POST['number']; + } else { + $number = ""; + } + if (isset($_POST['email']) and $_POST['email'] != "") + { + $email = $_POST['email']; + } else { + $_SESSION['error_msg'] .= "Vous n'avez pas entré d'adresse mail.\n"; + } +} else +{ + $_SESSION['error_msg'] .= "Attention, vous n'avez pas soumis le formulaire d'adhésion.\n"; +} + +if ($_SESSION['error_msg'] == "") +{ + create_member($name, $number, $email); +} +if ($_SESSION['error_msg'] != "") +{ + $_SESSION['error_msg'] .= "Veuillez réessayer."; + header('Location: /join'); +} else { + header('Location: /'); +} +?> \ No newline at end of file