-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_profile.php
103 lines (98 loc) · 4.25 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
103
<?php require 'lib/header.php';
$db_info = new DB('blog', 'user_info');
?>
<div class="container">
<?php
$data = $usr->fetch($db_info, 'id', Session::get('id'));
if (!is_bool($data)) {
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['update'])) {
$id = Session::get('id');
$address = trim($_POST['address']);
$skill = trim($_POST['skill']);
$quote = trim(($_POST['quote']));
if (empty($address) || empty($skill)) {
echo "<div class='alert alert-danger'>*Field must not be empty!</div>";
} elseif ($data['skill'] == $skill && $data['quote'] == $quote && $data['address'] == $address) {
echo "<div class='alert alert-warning'>Profile not updated!</div>";
header("Refresh:2 url=profile.php");
} else {
$info = ['id' => $id, 'address' => $address, 'skill' => $skill, 'quote' => $quote];
$result = $usr->updateProfile($db_info, $info);
if ($result) { ?>
<div class='alert alert-success'>Profile Updated....</div>
<?php header('Refresh:1 url=profile.php');
} else {
echo "<div class='alert alert-danger'>Ooops! There was an error!!</div>";
}
}
} ?>
<form action="" method="post" id="basic-info">
<div class="form-group" style="margin-top: 60px;">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Address</span>
</div>
<input type="text" class="form-control" name="address" id="address" value="<?php echo $data['address']; ?>">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Skill</span>
</div>
<textarea id="skill" name="skill" class="form-control"><?php echo $data['skill']; ?></textarea>
</div>
<div class="input-group" style="margin-top: 15px;">
<div class="input-group-prepend">
<span class="input-group-text">Quote</span>
</div>
<textarea id="quote" name="quote" class="form-control"><?php echo $data['quote']; ?></textarea>
</div>
<input type="submit" name="update" value="Update Profile" class="btn btn-primary" style="margin-top: 15px;">
</div>
</form>
<?php
} else {
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['update'])) {
$id = Session::get('id');
$address = $_POST['address'];
$skill = $_POST['skill'];
$quote = $_POST['quote'];
if (empty($address) || empty($skill)) {
echo "<div class='alert alert-danger'>*Field must not be empty!</div>";
} else {
$info = ['id' => $id, 'address' => $address, 'skill' => $skill, 'quote' => $quote];
$result = $usr->insertProfile($db_info, $info);
if ($result) { ?>
<div class='alert alert-success'>Profile Updated....</div>
<?php header('Location: profile.php');
} else {
echo "<div class='alert alert-danger'>Ooops! There was an error!!</div>";
}
}
} ?>
<form action="" method="post" id="basic-info">
<div class="form-group" style="margin-top: 60px;">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Address</span>
</div>
<input type="text" class="form-control" name="address" id="address" placeholder="Enter Your Full Address">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Skill</span>
</div>
<textarea id="skill" name="skill" class="form-control" placeholder="Enter your skills...." aria-label="Skill"></textarea>
</div>
<div class="input-group" style="margin-top: 15px;">
<div class="input-group-prepend">
<span class="input-group-text">Quote</span>
</div>
<textarea id="quote" name="quote" class="form-control" placeholder="Enter your favourite quote...." aria-label="quote"></textarea>
</div>
<input type="submit" name="update" value="Update Profile" class="btn btn-primary" style="margin-top: 15px;">
</div>
</form>
<?php
} ?>
</div>
<?php include 'lib/footer.php'; ?>