-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateAccountHandler.php
74 lines (63 loc) · 1.96 KB
/
updateAccountHandler.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
<?php
include 'database.php';
include 'user.php';
session_start();
if(!$_SESSION['logged_in']){
header('Location: index.php');
exit;
}
$_SESSION['errors'] = array();
$_SESSION['savedForm'] = array();
$_SESSION['succesfulForm'] = FALSE;
function checkZip($zip){
$result = preg_match("/^(\d{5}(?:\-\d{4})?)$/", $zip);
if($result){
return True;
}
return False;
}
if($_POST['email'] === ""){
$_SESSION['errors']['email'] = "*";
}
else if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
$_SESSION['errors']['email'] = "Invalid Email Address";
}
else{
$_SESSION['savedForm']['email'] = $_POST['email'];
}
if($_POST['address'] === ""){
$_SESSION['errors']['address'] = "*";
}
else{
$_SESSION['savedForm']['address'] = $_POST['address'];
}
if($_POST['city'] === ""){
$_SESSION['errors']['city'] = "*";
}
else{
$_SESSION['savedForm']['city'] = $_POST['city'];
}
$states = array("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY",
"LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA",
"RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY");
if(!isset($_POST['state']) || array_search($_POST["state"], $states) === FALSE){
$_SESSION['errors']['state'] = "You did not enter a valid state";
}
else{
$_SESSION['savedForm']['state'] = $_POST['state'];
}
if($_POST["zip"] === ""){
$_SESSION['errors']['zip'] = "*";
}
else if (!checkZip($_POST["zip"])){
$_SESSION['errors']['zip'] = "Invalid Zip Code";
}
if(count($_SESSION['errors'])){
$_SESSION['succesfulForm'] = FALSE;
}
else{
$_SESSION['succesfulForm'] = TRUE;
$dao = new Database();
$dao->updateUser($_SESSION['user']->getAccountID(), $_POST['email'], $_POST['address'], $_POST['city'], $_POST['state'], $_POST['zip']);
}
header('Location: manageUserInfo.php');