-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
108 lines (77 loc) · 2.31 KB
/
index.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
104
105
<?php
include 'includes/db.php';
?>
<div class="container">
<div class="jumbotron text-center">
<h2>Crud Application Using PHP</h2>
</div>
<br>
<a href="insert.php" role="button" class="btn btn-primary pull-right">INSERT DATA</a>
<br>
<br>
<table class="table table-hover table-striped">
<tr>
<th>ID</th>
<th>Name</th>
<th>Batch</th>
<th>Email</th>
<th>Image</th>
<th>Action</th>
</tr>
<?php
$query = "SELECT * FROM student ORDER BY id DESC ";
$result = mysqli_query($conn,$query);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$batch = $row['batch'];
$image = $row['image'];
?>
<tr>
<td><?=$id; ?></td>
<td><?=$name; ?></td>
<td><?=$email; ?></td>
<td><?=$batch; ?></td>
<td>
<img src= "<?= "images/".$image?>" alt="<?= $name ?>" class="thumbnail" width="100px" height="75px">
</td>
<td><a href="update.php?update=<?php echo $id ?>" class="btn btn-success btn-sm" role="button">Update</a>
<a href="index.php?delete=<?php echo $id ?>" class="btn btn-danger btn-sm" id="delete" role="button">Delete</a></td>
</tr>
<?php
}
}
if(isset($_GET['delete'])){
$id = $_GET['delete'];
$image = "SELECT * FROM student WHERE id = $id";
$query1 = mysqli_query($conn,$image);
while($row = mysqli_fetch_array($query1))
{
$img= $row['image'];
}
unlink("images/".$img);
$query = "DELETE FROM student WHERE id = $id";
$result = mysqli_query($conn,$query);
if($result){
header('location:index.php');
}
}
?>
</table>
</div>
<script>
$(document).ready(function(){
$('#delete').click(function(){
if(!confirm("do you want to delete?"))
{
return false;
}
else
{
return true;
}
});
});
</script>