-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateProfileProcess.php
89 lines (58 loc) · 2.51 KB
/
updateProfileProcess.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
<?php
session_start();
include "connection.php";
$email = $_SESSION["u"]["email"];
$fname = $_POST["f"];
$lname = $_POST["l"];
$mobile = $_POST["m"];
$line1 = $_POST["l1"];
$line2 = $_POST["l2"];
$provine = $_POST["p"];
$district = $_POST["d"];
$city = $_POST["c"];
$pcode = $_POST["pc"];
$user_rs = Database::search("SELECT * FROM `user` WHERE `email`='".$email."'");
if($user_rs->num_rows == 1){
Database::iud("UPDATE `user` SET `fname`='".$fname."',`lname`='".$lname."',`mobile`='".$mobile."' WHERE
`email`='".$email."'");
$address_rs = Database::search("SELECT * FROM `user_has_address` WHERE `user_email`='".$email."'");
if($address_rs->num_rows == 1){
Database::iud("UPDATE `user_has_address` SET `city_city_id`='".$city."',`line1`='".$line1."',
`line2`='".$line2."',`postal_code`='".$pcode."' WHERE `user_email`='".$email."'");
}else{
Database::iud("INSERT INTO `user_has_address`(`user_email`,`city_city_id`,`line1`,`line2`,`postal_code`)
VALUES ('".$email."','".$city."','".$line1."','".$line2."','".$pcode."')");
}
if(sizeof($_FILES) == 1){
$image = $_FILES["i"];
$image_extension = $image["type"];
$allowed_image_extensions = array("image/jpeg","image/png","image/svg+xml");
if(in_array($image_extension,$allowed_image_extensions)){
$new_img_extension;
if($image_extension == "image/jpeg"){
$new_img_extension = ".jpeg";
}else if($image_extension == "image/png"){
$new_img_extension = ".png";
}else if($image_extension == "image/svg+xml"){
$new_img_extension = ".svg";
}
$file_name = "resource/profile_image".$fname."_".uniqid().$new_img_extension;
move_uploaded_file($image["tmp_name"],$file_name);
$profile_img_rs = Database::search("SELECT * FROM `profile_img` WHERE `user_email`='".$email."'");
if($profile_img_rs->num_rows == 1){
Database::iud("UPDATE `profile_img` SET `path`='".$file_name."' WHERE `user_email`='".$email."'");
echo ("Updated");
}else{
Database::iud("INSERT INTO `profile_img`(`path`,`user_email`) VALUES ('".$file_name."','".$email."')");
echo ("Saved");
}
}
}else if(sizeof($_FILES) == 0){
echo ("You have not selected any image.");
}else{
echo ("You must select only 01 profile image.");
}
}else{
echo ("Invalid user.");
}
?>