-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.php
70 lines (64 loc) · 2.73 KB
/
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
include "inc/header.php";
include "lib/config.php";
include "lib/Database.php";
?>
<?php
$db = new Database();
$id = $_GET['id'];
$query = "SELECT * FROM tbl_user WHERE id = $id";
$getData = $db->select($query)->fetch_assoc();
if (isset($_POST['submit'])) {
$name = mysqli_real_escape_string($db->link, $_POST['name']);
$email = mysqli_real_escape_string($db->link, $_POST['email']);
$skill = mysqli_real_escape_string($db->link, $_POST['skill']);
if ($name == "" || $email == "" || $skill == "") {
$error= "<div class='alert alert-danger'>Field must be Empty !.</div>";
} else {
$query = "UPDATE tbl_user SET
name = '$name',
email = '$email',
skill = '$skill'
WHERE id = '$id'";
$updateData = $db->update($query);
}
}
?>
<?php
if (isset($_POST['delete'])) {
$query = "DELETE FROM tbl_user WHERE id = $id";
$deleteData = $db->delete($query);
}
?>
<div class="panel-heading">
<h2 style="width: 50%; display: inline-block;">Add Student </h2><a class="btn btn-primary text-right" style="float: right; display: inline-block; padding: 11px" href="index.php" class="text-right">Back</a>
</div>
<div class="panel-body">
<div style="width:60%; margin:0 auto;">
<?php
if (isset($error)) {
echo $error;
}
?>
<form action="update.php?id=<?php echo $id; ?>" method="POST">
<div class="form-group">
<label for="name">Name</label>
<input class="form-control" type="text" name="name" id="name" value="<?php echo $getData['name']; ?>">
</div>
<div class="form-group">
<label for="email">Email</label>
<input class="form-control" type="email" name="email" id="email" value="<?php echo $getData['email']; ?>">
</div>
<div class="form-group">
<label for="phone">Skill</label>
<input class="form-control" type="phone" name="skill" id="phone" value="<?php echo $getData['skill']; ?>">
</div>
<div class="form-group">
<input class="btn btn-info" type="submit" name="submit" value="Update">
<input class="btn btn-info" type="reset" value="Cancel">
<input class="btn btn-info" type="submit" name="delete" value="Delete">
</div>
</form>
</div>
</div>
<?php include "inc/footer.php" ?>