-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_profile.php
220 lines (172 loc) · 7.26 KB
/
action_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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
session_start();
include("functions.php");
include("includes/connection.php");
$user_id = $_SESSION['USER_ID'];
$sql = "SELECT user_type FROM user WHERE user_id ='$user_id' ";
$result_set = mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result_set)){
if($row['user_type'] == "Customer" || $row['user_type'] == 'Artist') {
$servername = "localhost";
$uname = "root";
$password = "";
$dbname = "online_art_gallery_database_final";
// Create connection
$conn = mysqli_connect($servername, $uname, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// In an application, this could be moved to a config file
$upload_errors = array(
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
if(isset($_POST['submit'])) {
// process the form data
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$upload_dir = "pictures/profile";
// You will probably want to first use file_exists() to make sure
// there isn't already a file by the same name.
// move_uploaded_file will return false if $tmp_file is not a valid upload file
// or if it cannot be moved for any other reason
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) {
$message = "File uploaded successfully.";
} else {
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}
}
$username = $_POST['username'];
$password = $_POST['password'];
$USER_FNAME= $_POST['Fname'];
$USER_MNAME= $_POST['Mname'];
$USER_LNAME= $_POST['Lname'];
$USER_GENDER= $_POST['gender'];
$USER_AGE= $_POST['age'];
$USER_EMAIL = $_POST['email'];
$USER_BDAY= $_POST['bday'];
$USER_CONTACT= $_POST['contact'];
$USER_CITY= $_POST['city'];
$USER_STATE= $_POST['state'];
$USER_PINCODE= $_POST['pincode'];
$USER_STREET= $_POST['Street'];
$USER_HOUSE_NUMBER= $_POST['House_num'];
$id = $_SESSION['USER_ID'];
$sql4="SELECT username FROM user WHERE user_id = $id";
$ss= mysqli_query($conn, $sql4);
while($aa = mysqli_fetch_array($ss)){
$temp_use = $aa['username'];
}
$sql3="UPDATE user SET username = 'NULL' WHERE user_id = $id";
$ss= mysqli_query($conn, $sql3);
$query = mysqli_query($conn, "SELECT * FROM user WHERE username= '" . $username . "' ") or die("Failed to query database ".mysqli_error($conn));
$count = mysqli_fetch_row($query);
if ($count>0) {
echo "<script type=\"text/javascript\">window.alert('Username Already Exists!');window.location.href = 'profile.php';</script>";
$sql3="UPDATE user SET username = '$temp_use' WHERE user_id = $id";
$ss= mysqli_query($conn, $sql3);
}
else{
$sql="UPDATE user SET username = '$username', password = '$password', USER_FNAME = '$USER_FNAME',USER_MNAME = '$USER_MNAME', USER_LNAME = '$USER_LNAME',USER_GENDER = '$USER_GENDER',
USER_AGE = '$USER_AGE',USER_BDAY = '$USER_BDAY',USER_CONTACT = '$USER_CONTACT',USER_CITY = '$USER_CITY',
USER_STATE = '$USER_STATE',USER_PINCODE = '$USER_PINCODE'= USER_STREET = '$USER_STREET',
USER_HOUSE_NUMBER = '$USER_HOUSE_NUMBER', USER_IMAGEPATH = '$target_file', USER_EMAIL = '$USER_EMAIL' WHERE USER_ID = $id" ;
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
redirect_to("profile.php");
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
}
else{
$servername = "localhost";
$uname = "root";
$password = "";
$dbname = "online_art_gallery_database_final";
// Create connection
$conn = mysqli_connect($servername, $uname, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// In an application, this could be moved to a config file
$upload_errors = array(
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
// process the form data
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$upload_dir = "pictures/profile";
// You will probably want to first use file_exists() to make sure
// there isn't already a file by the same name.
// move_uploaded_file will return false if $tmp_file is not a valid upload file
// or if it cannot be moved for any other reason
if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file)) {
$message = "File uploaded successfully.";
} else {
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}
$username = $_POST['username'];
$password = $_POST['password'];
$USER_FNAME= $_POST['Fname'];
$USER_MNAME= $_POST['Mname'];
$USER_LNAME= $_POST['Lname'];
$USER_GENDER= $_POST['gender'];
$USER_AGE= $_POST['age'];
$USER_EMAIL = $_POST['email'];
$USER_BDAY= $_POST['bday'];
$USER_CONTACT= $_POST['contact'];
$USER_CITY= $_POST['city'];
$USER_STATE= $_POST['state'];
$USER_PINCODE= $_POST['pincode'];
$USER_STREET= $_POST['Street'];
$USER_HOUSE_NUMBER= $_POST['House_num'];
$id = $_SESSION['edit_id'];
$sql4="SELECT username FROM user WHERE user_id = $id";
$ss= mysqli_query($conn, $sql4);
while($aa = mysqli_fetch_array($ss)){
$temp_use = $aa['username'];
}
$sql3="UPDATE user SET username = 'NULL' WHERE user_id = $id";
$ss= mysqli_query($conn, $sql3);
$query = mysqli_query($conn, "SELECT * FROM user WHERE username= '" . $username . "' ") or die("Failed to query database ".mysqli_error($conn));
$count = mysqli_fetch_row($query);
if ($count>0) {
echo "<script type=\"text/javascript\">window.alert('Username Already Exists!');window.location.href = 'profile.php';</script>";
$sql3="UPDATE user SET username = '$temp_use' WHERE user_id = $id";
$ss= mysqli_query($conn, $sql3);
}
else{
$sql="UPDATE user SET username = '$username', password = '$password', USER_FNAME = '$USER_FNAME',USER_MNAME = '$USER_MNAME', USER_LNAME = '$USER_LNAME',USER_GENDER = '$USER_GENDER',
USER_AGE = '$USER_AGE',USER_BDAY = '$USER_BDAY',USER_CONTACT = '$USER_CONTACT',USER_CITY = '$USER_CITY',
USER_STATE = '$USER_STATE',USER_PINCODE = '$USER_PINCODE' = USER_STREET = '$USER_STREET',
USER_HOUSE_NUMBER = '$USER_HOUSE_NUMBER', USER_IMAGEPATH = '$target_file', USER_EMAIL = '$USER_EMAIL' WHERE USER_ID = $id" ;
if (mysqli_query($conn, $sql)) {
echo "Record updated successfully";
redirect_to("edituser.php?id=$id");
} else {
echo "Error updating record: " . mysqli_error($conn);
}
mysqli_close($conn);
}
}
}
?>