-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate_customer.php
More file actions
131 lines (118 loc) · 4.53 KB
/
Update_customer.php
File metadata and controls
131 lines (118 loc) · 4.53 KB
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
<?php
//Get custmer information
$query = "SELECT custname, address, email, telephone
FROM customer
where username='".$_SESSION["us"]."'";
$result= pg_query($conn,$query) or die(pg_errormessage($conn));
$row = pg_fetch_array($result, NULL, PGSQL_ASSOC);
$us=$_SESSION["us"];
$email=$row["email"];
$fullname=$row["custname"];
$address=$row["address"];
$telephone=$row["telephone"];
//Update information when the user presses the "Update" button
if(isset($_POST["btnUpdate"])){
$fullname=$_POST['txtFullname'];
$address=$_POST['txtAddress'];
$tel=$_POST['txtTel'];
$test =check();
if($test=="")
{
if($_POST['txtPass1']!="")
{
$pass=md5($_POST['txtPass1']);
$sq="UPDATE customer SET custName='$fullname',address='$address',telephone='$telephone',
password ='$pass'
WHERE username = '".$_SESSION['us']."'";
pg_query($conn,$sq) or die(pg_errormessage($conn));
echo "<script>alert('Update Profile Successfully')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
}
else{
$sq="UPDATE customer SET custname='$fullname',address='$address',telephone='$telephone'
WHERE username = '".$_SESSION['us']."'";
pg_query($conn,$sq) or die(pg_errormessage($conn));
echo "<script>alert('Update Profile Successfully')</script>";
echo '<meta http-equiv="refresh" content="0;URL=index.php">';
}
echo '<meta http-equiv="refresh" content="0;URL=index.php" />';
}
else{
echo $test;
}
}
//Write check() function to check information
function check()
{
if($_POST['txtFullname']==""||$_POST['txtAddress']==""||$_POST['txtTel']=="")
{
return "<li>Enter Fullname or Address or Phone</li>";
}
elseif(strlen($_POST['txtPass1'])>0 && strlen($_POST['txtPass1'])<=5)
{
return "<li>Password is greater than 5 character</li>";
}
elseif($_POST['txtPass1']!=$_POST['txtPass2'])
{
return "<li>Password and Confirm Pass do not match</li>";
}
else {
return "";
}
}
?>
<div class="container">
<h2>Update Profile</h2>
<form id="form1" name="form1" method="post" action="" class="form-horizontal" role="form">
<div class="form-group">
<label for="lblTenDangNhap" class="col-sm-2 control-label">Username(*): </label>
<div class="col-sm-10">
<label class="form-control" style="font-weight:400"><?php echo $us; ?></label>
</div>
</div>
<div class="form-group">
<label for="lblEmail" class="col-sm-2 control-label">Email(*): </label>
<div class="col-sm-10">
<label class="form-control" style="font-weight:400"><?php echo $email; ?></label>
</div>
</div>
<div class="form-group">
<label for="lblMatKhau1" class="col-sm-2 control-label">Password: </label>
<div class="col-sm-10">
<input type="password" name="txtPass1" id="txtPass1" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="lblMatKhau2" class="col-sm-2 control-label">Confirm Password: </label>
<div class="col-sm-10">
<input type="password" name="txtPass2" id="txtPass2" class="form-control" />
</div>
</div>
<div class="form-group">
<label for="lblHoten" class="col-sm-2 control-label">Full name(*): </label>
<div class="col-sm-10">
<input type="text" name="txtFullname" id="txtFullname" value="<?php echo $fullname; ?>"
class="form-control" placeholder="Enter Fullname, please" />
</div>
</div>
<div class="form-group">
<label for="lblDiaChi" class="col-sm-2 control-label">Address(*): </label>
<div class="col-sm-10">
<input type="text" name="txtAddress" id="txtAddress" value="<?php echo $address; ?>"
class="form-control" placeholder="Enter Address, please" />
</div>
</div>
<div class="form-group">
<label for="lblDienThoai" class="col-sm-2 control-label">Telephone(*): </label>
<div class="col-sm-10">
<input type="text" name="txtTel" id="txtTel" value="<?php echo $telephone; ?>" class="form-control"
placeholder="Enter Telephone, please" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" name="btnUpdate" id="btnUpdate" value="Update" />
</div>
</div>
</form>
</div>