-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp-usr-blog.php
115 lines (101 loc) · 3.81 KB
/
php-usr-blog.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
<?php
error_reporting(0);
use MongoDB\Client;
require_once "vendor/autoload.php";
$conn = new Client("mongodb+srv://kimnhu:[email protected]/?serverSelectionTryOnce=false&serverSelectionTimeoutMS=15000&w=majority");
$db = $conn->IE104_PROJECT;
$post = $db->POST;
$account = $db->ACCOUNT;
$viewerid = 1;
$result_act = $account->findOne(['accountid' => $viewerid]);
$result_post = $post->find(['accountid' => $viewerid]);
if(isset($_POST['btn_info'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$facebook = $_POST['fb'];
$instagram = $_POST['ig'];
$twitter = $_POST['twitter'];
$check = false; //true if form has at least one changed input
if($fname != $result_act['firstname'] && $fname != '') {
$update = $account->updateOne(
['accountid' => $viewerid],
['$set' => ['firstname' => $fname]],
);
$check = true;
}
if($lname != $result_act['lastname'] && $lname != '') {
$update = $account->updateOne(
['accountid' => $viewerid],
['$set' => ['lastname' => $lname]],
);
$check = true;
}
if($email != $result_act['email'] && $email != '') {
$update = $account->updateOne(
['accountid' => $viewerid],
['$set' => ['email' => $email]],
);
$check = true;
}
if($facebook != $result_act['facebook'] && $facebook != '') {
$update = $account->updateOne(
['accountid' => $viewerid],
['$set' => ['facebook' => $facebook]],
);
$check = true;
}
if($instagram != $result_act['instagram'] && $instagram != '') {
$update = $account->updateOne(
['accountid' => $viewerid],
['$set' => ['instagram' => $instagram]],
);
$check = true;
}
if($twitter != $result_act['twitter'] && $twitter != '') {
$update = $account->updateOne(
['accountid' => $viewerid],
['$set' => ['twitter' => $twitter]],
);
$check = true;
}
if($check) {
?>
<div class="announce failed" id="announce">
<div class="form_announce">
<div class="content">
<h3>Update successfully.</h3>
<div class="btn close" style="display: flex; justify-content: center;">
<!-- <button id="close_announce">OK</button> -->
</div>
</div>
</div>
</div>
<?php
} else {
?>
<div class="announce failed" id="announce">
<div class="form_announce">
<div class="content">
<h3>No fields are changed.<br>Please check your update.</h3>
<div class="btn close" style="display: flex; justify-content: center;">
<!-- <button id="close_announce">OK</button> -->
</div>
</div>
</div>
</div>
<?php
}
echo "<meta http-equiv='refresh' content='0'>";
}
?>
<script>
document.getElementById("close_announce").addEventListener("click", function(){
document.getElementById("announce").classList.add("action");
})
document.addEventListener('keydown',function(e){
if (e.keyCode === 13) {
document.getElementById("announce").classList.add("action");
}
});
</script>