-
Notifications
You must be signed in to change notification settings - Fork 2
/
subscribe.php
73 lines (42 loc) · 1.44 KB
/
subscribe.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
<?php
include('config.php');
$db = mysqli_connect ($db_host, $db_user, $db_password, $db_name) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
$name = mysqli_real_escape_string($db,$_POST['name']);
$email = mysqli_real_escape_string($db,$_POST['email']);
if(empty($email) && empty($name)){
$status = "error";
$message = "Nothing was entered...";
}
else if(empty($email)){
$status = "error";
$message = "We need an email!";
}
else if(empty($name)){
$status = "error";
$message = "We need a name!";
}
else if((filter_var($email, FILTER_VALIDATE_EMAIL)) == FALSE ) {
$status = "error";
$message = "Sorry, invalid email";
}
else {
$sql = "SELECT * FROM CFT_email WHERE email_address='$email'";
$existingSignup = mysqli_query($db,$sql);
if(mysqli_num_rows($existingSignup) > 1){
$status = "error";
$message = "This email is already registered";
}
else {
$sql = "INSERT INTO CFT_email (email_name, email_address) VALUES ('$name','$email')";
mysqli_query($db,$sql);
$status = "success";
$message = "Thanks! You've been added to our list and we'll be sending you updates soon.";
}
}
$json = array(
'status' => $status,
'message' => $message
);
$output = json_encode($json);
echo $output;
?>