· 7 years ago · Dec 29, 2018, 05:42 AM
1<?php
2
3if(!isset($fName) && !isset($lName) && !isset($zip) && !isset($email) &&
4 !isset($password)) {
5 $fName = '';
6 $lName = '';
7 $zip = '';
8 $email = '';
9 $password = '';
10}
11
12?>
13
14<!DOCTYPE html>
15<html>
16<head>
17 <meta charset="utf-8" />
18 <meta http-equiv="X-UA-Compatible" content="IE=edge">
19 <title>Register</title>
20 <meta name="viewport" content="width=device-width, initial-scale=1">
21 <link rel="stylesheet" type="text/css" media="screen" href="/CentralPerk/main.css" />
22 <link rel="stylesheet" type="text/css" media="screen" href="formstyles.css" />
23 <script src="main.js"></script>
24</head>
25<body>
26 <div id="aside">
27 <h1>Register For An Account</h1>
28 </div>
29
30 <form action="index.php" method="post" id="registration_form">
31 <input type="hidden" name="action" value="register">
32
33 <label>Personal Information</label>
34 <br>
35 <br>
36
37 <input type="text" name="fName" placeholder="First Name" required
38 value="<?php echo htmlspecialchars($fName); ?>" />
39 <br>
40 <br>
41
42 <input type="text" name="lName" placeholder="Last Name" required
43 value="<?php echo htmlspecialchars($lName); ?>" />
44 <br>
45 <br>
46
47 <input name="zip" id="zipcode" type="text" placeholder="Zipcode" required
48 pattern="^d{5}(-d{4})?$"
49 value="<?php echo htmlspecialchars($zip); ?>" />
50 <br>
51 <br>
52
53 <label>Account Information</label>
54 <br>
55 <br>
56
57 <input type="email" name="email" placeholder="Email Address" required
58 value="<?php echo htmlspecialchars($email); ?>" />
59 <br>
60 <br>
61
62 <input type="password" name="password" placeholder="password" required
63 value="<?php echo htmlspecialchars($password); ?>" />
64 <br>
65 <br>
66
67 </form>
68
69 <button type="submit" form="registration_form" value="Submit">Submit</button>
70
71</body>
72</html>
73
74<?php
75require('../model/database.php');
76require('../model/account_db.php');
77
78//form value is 'action'
79$action = filter_input(INPUT_POST, 'action');
80
81if($action == 'register') {
82 $fName = filter_input(INPUT_POST, 'fName');
83 $lName = filter_input(INPUT_POST, 'lName');
84 $zip = filter_input(INPUT_POST, 'zip', FILTER_VALIDATE_INT);
85 $email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
86 $password = filter_input(INPUT_POST, 'password');
87
88//this is where I am trying to determine if the email entered already exists,
89//if it does not, it executes the add_user method in the account_db.php file
90
91$checkUserEmail = $db -> query("SELECT UserEmail FROM Users
92 WHERE `UserEmail` = $email");
93
94if ($checkUserEmail === TRUE) {
95 $message = "User already exists";
96 include('../model/test.php');
97}
98else {
99 add_user($fName, $lName, $zip, $email);
100 header('../CentralPerk/index.php');
101}
102
103}
104?>
105
106<?php
107
108function add_user($fName, $lName, $zip, $email) {
109 global $db;
110 $query = 'INSERT INTO Users
111 (UserFirstName, UserLastName, UserZipcode, UserEmail)
112 VALUES
113 (:fName, :lName, :zip, :email)';
114 $statement = $db->prepare($query);
115 $statement->bindValue(':fName', $fName);
116 $statement->bindValue(':lName', $lName);
117 $statement->bindValue(':zip', $zip);
118 $statement->bindValue(':email', $email);
119 $statement->execute();
120 $statement->closeCursor();
121}
122
123?>
124
125DROP DATABASE IF EXISTS accounts;
126CREATE DATABASE accounts;
127USE accounts;
128
129GRANT SELECT, INSERT, UPDATE, DELETE
130ON *
131TO mgs_user@localhost
132IDENTIFIED BY 'pa55word';
133
134CREATE TABLE Users (
135 UserID BIGINT NOT NULL AUTO_INCREMENT,
136 UserFirstName VARCHAR(60) NOT NULL,
137 UserLastName VARCHAR(60) NOT NULL,
138 UserZipcode INT NOT NULL,
139 UserEmail VARCHAR(60) NOT NULL,
140 PRIMARY KEY(UserID)
141
142);
143
144 CREATE UNIQUE INDEX user_idx ON Users (
145 UserEmail
146);