-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile_verify.php
executable file
·68 lines (59 loc) · 2.11 KB
/
profile_verify.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
<?php
session_start();
include 'dbconnect.php';
if(isset($_POST['update'])){
$username=$_SESSION['username'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$first="/^[A-Za-z]{1,}$/";
$last="/^[A-Za-z]{1,}$/";
if(!preg_match($first,$first_name)||!preg_match($last,$last_name)){
$_SESSION['message']="Please Enter Valid Charachters";
header("Location:profile.php");
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$first_name=test_input($first_name);
$last_name=test_input($last_name);
if(isset($_FILES['avatar'])){
$avatar=$_FILES['avatar'];
$avatar_size=$avatar['size'];
$avatar_name=$avatar['name'];
$avatar_tmp_name=$avatar['tmp_name'];
$avatar_type=$avatar['type'];
if($avatar_type=="image/jpg"||$avatar_type=="image/jpeg"||$avatar_type=="image/png"){
if($avatar_size<=2000000){
move_uploaded_file($avatar_tmp_name,"avatar/".$avatar_name);
$sql="UPDATE kunal_user set first_name='$first_name',last_name='$last_name',avatar='$avatar_name' where username='$username';";
// echo $sql; die();
$result=mysqli_query($conn,$sql);
if($result){
header("Location:home.php");
}
else{
$_SESSION['message']="Profile Update Failed";
header("Location:profile.php");
}
}
else{
$_SESSION['message']="Image size is greater than 2mb";
header("Location:profile.php");
}
}
else{
$_SESSION['message']="Image is not in valid format";
header("Location:profile.php");
}
}
else{
$_SESSION['message']="Please Upload File";
header('Location:profile.php');
}
}
else{
header("Location:index.php");
}