-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_profile.php
170 lines (154 loc) · 8.18 KB
/
update_profile.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php require_once('header.php'); ?>
<?php
//Kiểm tra xem khách hàng đã đăng nhập hay chưa
if(!isset($_SESSION['customer'])) {
header('location: '.BASE_URL.'logout.php');
exit;
}
else {
// Nếu khách hàng đã đăng nhập mà trạng thái tài khoản bằng 0 thì buộc người dùng đăng xuất
$statement = $pdo->prepare("SELECT * FROM khachhang WHERE kh_id=? AND kh_trangthai=?");
$statement->execute(array($_SESSION['customer']['kh_id'],0));
$total = $statement->rowCount();
if($total) {
header('location: '.BASE_URL.'logout.php');
exit;
}
}
?>
<?php
//Kiểm tra và cập nhật lại thông tin khách hàng
if (isset($_POST['form1'])) {
$giatri = 1;
if(empty($_POST['cust_name'])) {
$giatri = 0;
$error_message .= "Tên không được để trống!"."<br>";
}
if(empty($_POST['cust_phone'])) {
$giatri = 0;
$error_message .= "Số điện thoại không được để trống!"."<br>";
}
if(empty($_POST['cust_address'])) {
$giatri = 0;
$error_message .= "Địa chỉ không được để trống!"."<br>";
}
if(empty($_POST['cust_country'])) {
$giatri = 0;
$error_message .= "Bạn vui lòng chọn 1 quốc gia!"."<br>";
}
if(empty($_POST['cust_city'])) {
$giatri = 0;
$error_message .= "Thành phố không được để trống!"."<br>";
}
if(empty($_POST['cust_state'])) {
$giatri = 0;
$error_message .= "Quận không được để trống!"."<br>";
}
if(empty($_POST['cust_zip'])) {
$giatri = 0;
$error_message .= "Mã Zip không được để trống!"."<br>";
}
// Cập nhật thông tin vào database
if ($giatri == 1) {
$statement = $pdo->prepare("UPDATE khachhang SET kh_ten=?, kh_cty=?, kh_sodienthoai=?, kh_quocgia=?, kh_diachi=?, kh_thanhpho=?, kh_quan=?, kh_zip=? WHERE kh_id=?");
$statement->execute(array(
strip_tags($_POST['cust_name']),
strip_tags($_POST['cust_cname']),
strip_tags($_POST['cust_phone']),
strip_tags($_POST['cust_country']),
strip_tags($_POST['cust_address']),
strip_tags($_POST['cust_city']),
strip_tags($_POST['cust_state']),
strip_tags($_POST['cust_zip']),
$_SESSION['customer']['kh_id']
));
$success_message = "Cập nhật profile thành công!!";
$_SESSION['customer']['kh_ten'] = $_POST['cust_name'];
$_SESSION['customer']['kh_cty'] = $_POST['cust_cname'];
$_SESSION['customer']['kh_sodienthoai'] = $_POST['cust_phone'];
$_SESSION['customer']['kh_quocgia'] = $_POST['cust_country'];
$_SESSION['customer']['kh_diachi'] = $_POST['cust_address'];
$_SESSION['customer']['kh_thanhpho'] = $_POST['cust_city'];
$_SESSION['customer']['kh_quan'] = $_POST['cust_state'];
$_SESSION['customer']['kh_zip'] = $_POST['cust_zip'];
}
}
?>
<div class="page">
<div class="container">
<div class="row">
<div class="col-md-12">
<?php require_once('khachhang_sidebar.php'); ?>
</div>
<div class="col-md-12">
<div class="user-content">
<h3>
<?php echo "Cập nhật thông tin cá nhân" ?>
</h3>
<?php
if($error_message != '') {
echo "<div class='error' style='padding: 10px;background:#f1f1f1;margin-bottom:20px;'>".$error_message."</div>";
}
if($success_message != '') {
echo "<div class='success' style='padding: 10px;background:#f1f1f1;margin-bottom:20px;'>".$success_message."</div>";
}
?>
<form action="" method="post">
<div class="row">
<div class="col-md-6 form-group">
<label for=""><?php echo "Tên" ?> *</label>
<input type="text" class="form-control" name="cust_name" value="<?php echo $_SESSION['customer']['kh_ten']; ?>">
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Tên công ty"; ?></label>
<input type="text" class="form-control" name="cust_cname" value="<?php echo $_SESSION['customer']['kh_cty']; ?>">
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Email"; ?> *</label>
<input type="text" class="form-control" name="" value="<?php echo $_SESSION['customer']['kh_email']; ?>" disabled>
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Số điện thoại"; ?> *</label>
<input type="number" class="form-control" name="cust_phone" value="<?php echo $_SESSION['customer']['kh_sodienthoai']; ?>">
</div>
<div class="col-md-12 form-group">
<label for=""><?php echo "Địa chỉ"; ?> *</label>
<textarea name="cust_address" class="form-control" cols="30" rows="10" style="height:70px;"><?php echo $_SESSION['customer']['kh_diachi']; ?></textarea>
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Quốc gia"; ?> *</label>
<select name="cust_country" class="form-control">
<option value="">Chọn quốc gia</option>
<?php
$statement = $pdo->prepare("SELECT * FROM quocgia ORDER BY country_name ASC");
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
?>
<option value="<?php echo $row['country_id']; ?>" <?php if($row['country_id'] == $_SESSION['customer']['kh_quocgia']) {echo 'selected';} ?>><?php echo $row['country_name']; ?></option>
<?php
}
?>
</select>
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Thành phố"; ?> *</label>
<input type="text" class="form-control" name="cust_city" value="<?php echo $_SESSION['customer']['kh_thanhpho']; ?>">
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Quận"; ?> *</label>
<input type="text" class="form-control" name="cust_state" value="<?php echo $_SESSION['customer']['kh_quan']; ?>">
</div>
<div class="col-md-6 form-group">
<label for=""><?php echo "Mã zip"; ?> *</label>
<input type="text" class="form-control" name="cust_zip" value="<?php echo $_SESSION['customer']['kh_zip']; ?>">
</div>
</div>
<input type="submit" class="btn btn-primary" value="<?php echo "Cập nhật"; ?>" name="form1">
</form>
</div>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>