-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_my.php
136 lines (103 loc) · 4.69 KB
/
edit_my.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
require __DIR__. '/_db_connetion.php';
$page_name = 'edit_my';
$sql = "SELECT * FROM `members` WHERE `sid`=". intval($_SESSION['loginUser']['sid']);
$row = $pdo->query($sql)->fetch(PDO::FETCH_ASSOC);
if(empty($row)){
header('Location: ./');
exit;
}
?>
<?php include __DIR__. '/__html_header.php' ?>
<?php include __DIR__. '/__html_nav.php' ?>
<div class="container">
<div class="row" style="margin-top: 2rem;">
<div class="col-lg-6">
<div class="card">
<div class="alert alert-success" role="alert" id="alertInfo" style="display:none;"> </div>
<div class="card-body">
<h5 class="card-title">個人資料修改</h5>
<form method="post" onsubmit="return checkform()">
<div class="form-group">
<input type="hidden" name="sid" value="<?= $row['sid'] ?>">
<label for="email">信箱(帳號)</label>
<input type="email" class="form-control" id="email" name="email" value="<?= htmlentities($row['email']) ?>" disable>
<small class="form-text"></small>
</div>
<div class="form-group">
<label for="nickname">*暱稱</label>
<input type="text" class="form-control" id="nickname" name="nickname" value="<?= htmlentities($row['nickname']) ?>">
<small class="form-text"></small>
</div>
<div class="form-group">
<label for="mobile">電話</label>
<input type="text" class="form-control" id="mobile" name="mobile" value="<?= htmlentities($row['mobile']) ?>">
<small class="form-text"></small>
</div>
<div class="form-group">
<label for="birthday">生日</label>
<input type="text" class="form-control" id="birthday" name="birthday" value="<?= htmlentities($row['birthday']) ?>">
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
</div>
<div class="address">
<label for="address">住址</label>
<textarea type="text" class="form-control" rows=5 id="address" name="address" ><?= htmlentities($row['address']) ?></textarea>
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
</div>
<div class="form-group">
<label for="password">*原密碼</label>
<input type="password" class="form-control" id="password" name="password" >
<small class="form-text"></small>
</div>
<button type="submit" class="btn btn-primary my-3" id="submitBtn">資料修改</button>
</form>
</div>
</div>
</div>
</div>
</div>
<?php include __DIR__. '/__html_script.php' ?>
<script>
var alertInfo=$("#alertInfo");
var submitBtn = $('#submitBtn');
var $nickname=$("#nickname");
var $password=$("#password");
var file=[$nickname,$password];
function checkform(){
file.forEach(function(val){
val.next().text('');
});
alertInfo.hide();
// submitBtn.hide();
var ispass=true;
var mobileRegex = /^09\d{2}\-?\d{3}\-?\d{3}$/;
if($nickname.val().length<2){
ispass=false;
$nickname.next().text("輸入長度太短");
}
if($password.val().length<6){
ispass=false;
$password.next().text("密碼長度太短");
}
if(ispass){
$.post('edit_my_api.php',$(document.forms[0]).serialize(),function(data){
console.log(data);
// alert(data.info);
if(data.success){
// location.href = 'data_list.php';
alertInfo.removeClass("alert-danger");
alertInfo.addClass("alert-success");
$('#my_nickname').text($nickname.val());
}else{
alertInfo.removeClass("alert-success");
alertInfo.addClass("alert-danger");
}
alertInfo.text(data.info);
alertInfo.show();
submitBtn.show();
},'json')
}
return false;
}
</script>
<?php include __DIR__. '/__html_footer.php' ?>