-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign-up-api.php
executable file
·58 lines (44 loc) · 1.3 KB
/
sign-up-api.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
<?php
require './parts/connect-db.php';
$output = [
'success' => false,
'error' => '',
'code' => 0,
'postData' => $_POST, // 確認資料
];
header('Content-Type: application/json');
if (empty($_POST['user_name'])) {
$output['error'] = '沒有姓名資料';
echo json_encode($output, JSON_UNESCAPED_UNICODE);
exit;
}
if (empty($_POST['user_email'])) {
$output['error'] = '沒有信箱資料';
echo json_encode($output, JSON_UNESCAPED_UNICODE);
exit;
}
if (empty($_POST['user_password'])) {
$output['error'] = '沒有設定密碼';
echo json_encode($output, JSON_UNESCAPED_UNICODE);
exit;
}
if (empty($_POST['user_mobile'])) {
$output['error'] = '沒有輸入手機';
echo json_encode($output, JSON_UNESCAPED_UNICODE);
exit;
}
$sql = "INSERT INTO `members`( `user_name`, `user_email`, `user_password`, `user_mobile`, `create_at`) VALUES ( ?, ?, ?, ?, NOW())";
$stmt = $pdo->prepare($sql);
$stmt->execute([
$_POST['user_name'],
$_POST['user_email'],
$_POST['user_password'],
$_POST['user_mobile'],
]);
$output['rowCount'] = $stmt->rowCount();
if ($stmt->rowCount() == 1) {
$output['success'] = true;
} else {
$output['error'] = '新增失敗';
};
echo json_encode($output);