-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_profile.php
102 lines (85 loc) · 3.32 KB
/
update_profile.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
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
require_once __DIR__ . '/config/app.php';
require_once __DIR__ . '/guards/authenticated.php';
require_once __DIR__ . '/config/db.php';
$title = 'Perbarui Profile';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$query_update = "UPDATE users SET name = '$name', email = '$email' WHERE id = {$_SESSION['user']['id']}";
if (mysqli_query($conn, $query_update)) {
$_SESSION['user']['name'] = $name;
$_SESSION['user']['email'] = $email;
header("Location: profile.php");
exit;
} else {
$error = 'Gagal.';
}
} else {
$query_profile = mysqli_query($conn, "SELECT name, email FROM users WHERE id = {$_SESSION['user']['id']}");
if ($profile = mysqli_fetch_assoc($query_profile)) {
$name = $profile['name'];
$email = $profile['email'];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= $title ?> | InventarisKu</title>
<?php require_once __DIR__ . '/partials/head.php' ?>
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
<?php require_once __DIR__ . '/partials/topbar.php' ?>
<?php require_once __DIR__ . '/partials/sidebar.php' ?>
<div class="content-wrapper">
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1><?= $title ?></h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="./index.php">Dashboard</a></li>
<li class="breadcrumb-item active"><?= $title ?></li>
</ol>
</div>
</div>
</div>
</section>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div class="card card-primary card-outline">
<div class="card-body box-profile">
<?php if (isset($error)) : ?>
<div class="alert alert-danger"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="post" action="update_profile.php">
<div class="form-group">
<label for="name">Nama</label>
<input type="text" name="name" id="name" class="form-control" value="<?= htmlspecialchars($name) ?>" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control" value="<?= htmlspecialchars($email) ?>" required>
</div>
<button type="submit" class="btn btn-primary btn-block">Simpan</button>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php require_once __DIR__ . '/partials/footer.php' ?>
</div>
<?php require_once __DIR__ . '/partials/body.php' ?>
</body>
</html>