1if (isset($_GET['del'])) {
2 $id = $_GET['del'];
3 mysqli_query($db, "DELETE FROM info WHERE id=$id");
4 $_SESSION['message'] = "Address deleted!";
5 header('location: index.php');
6}
1<?php
2// Check if the form is submitted
3$personName = $_POST['personName'];
4$address = $_POST['address'];
5$mobile = $_POST['mobile'];
6$email = $_POST['email'];
7$message = $_POST['message'];
8$tdate=new DateTime();
9// form a sql query
10$sql = "INSERT INTO tbquery (name, email, mobile,address, comment, postdate)
11VALUES ('". $personName."',
12'". $email ."',
13'". $mobile ."',
14'". $address ."',
15'". $message ."',
16'". $tdate->format('Y-m-d') ."'
17)";
18if (mysqli_query($conn, $sql)) {
19echo "Your query posted successfully";
20} else {
21echo "Error: " . $sql . "" . mysqli_error($conn);
22}
23
24mysqli_close($conn);
25
26?>
27
1// ...
2<body>
3<?php if (isset($_SESSION['message'])): ?>
4 <div class="msg">
5 <?php
6 echo $_SESSION['message'];
7 unset($_SESSION['message']);
8 ?>
9 </div>
10<?php endif ?>
1<?php $results = mysqli_query($db, "SELECT * FROM info"); ?>
2
3<table>
4 <thead>
5 <tr>
6 <th>Name</th>
7 <th>Address</th>
8 <th colspan="2">Action</th>
9 </tr>
10 </thead>
11
12 <?php while ($row = mysqli_fetch_array($results)) { ?>
13 <tr>
14 <td><?php echo $row['name']; ?></td>
15 <td><?php echo $row['address']; ?></td>
16 <td>
17 <a href="index.php?edit=<?php echo $row['id']; ?>" class="edit_btn" >Edit</a>
18 </td>
19 <td>
20 <a href="server.php?del=<?php echo $row['id']; ?>" class="del_btn">Delete</a>
21 </td>
22 </tr>
23 <?php } ?>
24</table>
25
26<form>
27 // ...
1// ...
2
3if (isset($_POST['update'])) {
4 $id = $_POST['id'];
5 $name = $_POST['name'];
6 $address = $_POST['address'];
7
8 mysqli_query($db, "UPDATE info SET name='$name', address='$address' WHERE id=$id");
9 $_SESSION['message'] = "Address updated!";
10 header('location: index.php');
11}