-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile_update.php
54 lines (46 loc) · 1.32 KB
/
profile_update.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
<?php
include 'includes/session.php';
if(isset($_GET['return'])){
$return = $_GET['return'];
}
else{
$return = 'home.php';
}
if(isset($_POST['save'])){
$curr_password = $_POST['curr_password'];
$reg_no = $_POST['voters_reg_no'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$photo = $_FILES['photo']['name'];
if(password_verify($curr_password, $voters_reg_no['password'])){
if(!empty($photo)){
move_uploaded_file($_FILES['photo']['tmp_name'], 'images/'.$photo);
$filename = $photo;
}
else{
$filename = $voters_reg_no['photo'];
}
if($password == $voters_reg_no['password']){
$password = $voters_reg_no['password'];
}
else{
$password = password_hash($password, PASSWORD_DEFAULT);
}
$sql = "UPDATE voters SET password = '$password', firstname = '$firstname', lastname = '$lastname', photo = '$filename' WHERE id = '".$voters_reg_no['id']."'";
if($conn->query($sql)){
$_SESSION['success'] = 'Voters profile updated successfully';
}
else{
$_SESSION['error'] = $conn->error;
}
}
else{
$_SESSION['error'] = 'Incorrect password';
}
}
else{
$_SESSION['error'] = 'Fill up required details first';
}
header('location:'.$return);
?>