-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_profile.php
More file actions
86 lines (73 loc) · 3 KB
/
Copy pathedit_profile.php
File metadata and controls
86 lines (73 loc) · 3 KB
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
<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
header('Location: login.php');
exit;
}
include 'functions.php';
$pdo = pdo_connect_mysql();
$msg = '';
if (isset($_SESSION['msg'])) {
$msg = $_SESSION['msg'];
$_SESSION['msg'] = '';
}
// Get exists data
$stmt = $pdo->prepare('SELECT name, npm, prodi, username, email FROM accounts WHERE id = ?');
$stmt->execute([$_GET['id']]);
$user = $stmt->fetch();
if (!empty($_POST)) {
if ($_SESSION['id'] != $_GET['id']){
$_SESSION['msg'] = 'Invalid ID!';
header('Location: edit_profile.php');
exit;
}
$stmt = $pdo->prepare('UPDATE accounts SET name = ?, npm = ?, prodi = ?, username = ?, email = ? WHERE id = ?');
if ($stmt->execute([$_POST['name'], $_POST['npm'], $_POST['prodi'], $_POST['username'], $_POST['email'], $_GET['id']])) {
$_SESSION['msg'] = 'Profile update successfully!';
header('Location: profile.php');
exit;
} else {
exit('Samting wen wrong sar');
}
}
?>
<?=template_header('Edit Profile')?>
<div class="container-fluid content">
<?php if ($msg): ?>
<p><?=$msg?></p>
<?php endif;?>
<h2><i class="fa fa-user-edit fa-lg" style="margin-right: 10px;"></i>Edit Profile</h2>
<div>
<form action="edit_profile.php?id=<?=$_SESSION['id']?>" method="post">
<div class="form-group">
<label for="name">Nama Lengkap</label>
<input type="text" class="form-control" name="name" id="name" value="<?=$user['name']?>" required>
</div>
<div class="form-group">
<label for="npm">NPM</label>
<input type="text" class="form-control" name="npm" id="npm" value="<?=$user['npm']?>" required>
</div>
<div class="form-group">
<label for="prodi">Prodi</label>
<select class="form-control" name="prodi" required>
<?php
$options = array('Sistem Informasi', 'Manajemen', 'Akuntansi', 'Pariwisata', 'Ilmu Hukum', 'Teknik Elektro', 'Teknologi Informasi', 'Teknik Sipil', 'Arsitektur', 'Pendidikan Bahasa Inggris');
foreach($options as $option) {
echo '<option value="'. $option .'"'. ($option == $user['prodi'] ? 'selected' : '') .'>'. $option .'</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" name="username" id="username" value="<?=$user['username']?>" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" id="email" value="<?=$user['email']?>" required>
</div>
<input type="submit" class="btn btn-success" value="Update">
</form>
</div>
</div>
<?=template_footer()?>