-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm_Update_Delete_Search.php
125 lines (87 loc) · 2.45 KB
/
Form_Update_Delete_Search.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Display Data</title>
</head>
<body>
<form action="" method="post">
<input type="text" placeholder="Searching.." name="searched" ><br>
<button name="search">Search</button><br>
</form>
<table>
<tr>
<th>Id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
<?php
if(isset($_POST['search'])){
$searchName=$_POST['searched'];
}
$con=mysqli_connect('localhost','root','','buet');
$result=mysqli_query($con,"SELECT * FROM `cse` WHERE fname LIKE '%$searchName%'");
while($row=mysqli_fetch_assoc($result)):
?>
<tr>
<td><?php echo $row['id']; ?> </td>
<td> <?php echo $row['fname']; ?></td>
<td> <?php echo $row['lname']; ?></td>
<td><a href="delete.php?deleteid=<?php echo $row['id']; ?>">Delete</a></td>
<td><a href="update.php?updateid=<?php echo $row['id']; ?>">Update</a></td>
</tr>
<?php endwhile; ?>
</table>
</body>
</html>
<?php
$did=$_GET['deleteid'];
$con=mysqli_connect('localhost','root','','buet');
$result=mysqli_query($con,"delete from cse where id='$did'");
if($result){
echo "Delete Successfully";
}
else{
echo "Delete Unsuccessful";
}
?>
<?php
$uid=$_GET['updateid'];
$con=mysqli_connect('localhost','root','','buet');
$result=mysqli_query($con,"select * from cse where id='$uid'");
$row=mysqli_fetch_assoc($result);
$firstname=$row['fname'];
$lastname=$row['lname'];
if(isset($_POST['update'])){
$first=$_POST['firstname'];
$last=$_POST['lastname'];
$con=mysqli_connect('localhost','root','','buet');
$query=mysqli_query($con,"update cse set id='$uid',fname='$first',lname='$last' where id='$uid'");
if($query){
echo "Update Successfully..";
}
else{
echo "Update Unsuccessufully..";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Form</title>
</head>
<body>
<form action="" method="post">
<div>
<input type="text" name="firstname" value="<?php echo $firstname;?>" autofocus>
</div><br>
<div>
<input type="text" name="lastname" value="<?php echo $lastname;?>">
</div><br><br>
<input type="submit" name="update" value="Update"><br>
</form>
</body>
</html>