-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile_edit.php
56 lines (46 loc) · 1.45 KB
/
profile_edit.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
<!-- Done -->
<?php
include 'includes/session.php';
$conn = $pdo->open();
if(isset($_POST['edit'])){
$curr_password = $_POST['curr_password'];
$email = $_POST['email'];
$password = $_POST['password'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$contact = $_POST['contact'];
$address = $_POST['address'];
$photo = $_FILES['photo']['name'];
if(password_verify($curr_password, $user['password'])){
if(!empty($photo)){
move_uploaded_file($_FILES['photo']['tmp_name'], 'images/'.$photo);
$filename = $photo;
}
else{
$filename = $user['photo'];
}
if($password == $user['password']){
$password = $user['password'];
}
else{
$password = password_hash($password, PASSWORD_DEFAULT);
}
try{
$stmt = $conn->prepare("UPDATE users SET email=:email, password=:password, firstname=:firstname, lastname=:lastname, contact_info=:contact, address=:address, photo=:photo WHERE id=:id");
$stmt->execute(['email'=>$email, 'password'=>$password, 'firstname'=>$firstname, 'lastname'=>$lastname, 'contact'=>$contact, 'address'=>$address, 'photo'=>$filename, 'id'=>$user['id']]);
$_SESSION['success'] = 'Account updated successfully';
}
catch(PDOException $e){
$_SESSION['error'] = $e->getMessage();
}
}
else{
$_SESSION['error'] = 'Incorrect password';
}
}
else{
$_SESSION['error'] = 'Fill up edit form first';
}
$pdo->close();
header('location: profile.php');
?>