-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_submit.php
114 lines (108 loc) · 2.89 KB
/
service_submit.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php include 'include/db_connect_oo.php'; ?>
<?php
function sendEmail($email, $id) {
$msg = "Entry $id Inserted.";
$msg = wordwrap($msg,70);
// send email if email is valid
if (isValidEmail($email)) {
mail($email, "Entry $id Inserted.", $msg);
}
}
function isValidEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match('/@.+\./', $email);
}
?>
<?php
header('Content-Type: application/json');
$post_data = array();
// read post data
foreach ($_POST as $key => $value) {
// echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
$post_data[htmlspecialchars($key)] = htmlspecialchars($value);
}
// save to db
$sql = "INSERT INTO data_entry (
key_name,
key_email,
key_qa1,
key_qa1_e1,
key_qa1_e2,
key_qa2,
key_qa2_e1,
key_qa3,
key_qa3_e1,
key_qa3_e2,
key_qa3_e3,
key_qa4,
key_qa4_e1,
key_qa4_e2,
key_qae,
key_qb1,
key_qb1_e1,
key_qb1_e2,
key_qb1_e3,
key_qb1_e4,
key_qb1e,
key_qb2,
key_qb2_e1,
key_qb2_e2,
key_qb2e,
key_qc1,
key_qc1_e1,
key_qc1_e2,
key_qc1_e3,
key_qc1e,
key_qc2,
key_qc2_e1,
key_qc2_e2,
key_qc2_e3,
key_qc2_e4,
key_qc2e
)
VALUES (
'$post_data[key_name]',
'$post_data[key_email]',
'$post_data[key_qa1]',
'$post_data[key_qa1_e1]',
'$post_data[key_qa1_e2]',
'$post_data[key_qa2]',
'$post_data[key_qa2_e1]',
'$post_data[key_qa3]',
'$post_data[key_qa3_e1]',
'$post_data[key_qa3_e2]',
'$post_data[key_qa3_e3]',
'$post_data[key_qa4]',
'$post_data[key_qa4_e1]',
'$post_data[key_qa4_e2]',
'$post_data[key_qae]',
'$post_data[key_qb1]',
'$post_data[key_qb1_e1]',
'$post_data[key_qb1_e2]',
'$post_data[key_qb1_e3]',
'$post_data[key_qb1_e4]',
'$post_data[key_qb1e]',
'$post_data[key_qb2]',
'$post_data[key_qb2_e1]',
'$post_data[key_qb2_e2]',
'$post_data[key_qb2e]',
'$post_data[key_qc1]',
'$post_data[key_qc1_e1]',
'$post_data[key_qc1_e2]',
'$post_data[key_qc1_e3]',
'$post_data[key_qc1e]',
'$post_data[key_qc2]',
'$post_data[key_qc2_e1]',
'$post_data[key_qc2_e2]',
'$post_data[key_qc2_e3]',
'$post_data[key_qc2_e4]',
'$post_data[key_qc2e]'
)";
if ($conn->query($sql) === TRUE) {
$post_data["id"] = $conn->insert_id;
} else {
$post_data["sql"] = $sql;
$post_data["error"] = $conn->error;
}
$conn->close();
echo json_encode($post_data);
?>