I want there is a delete button in every row in table and when click the button for example in row 1 then the row 1 deleted.
and EXTRA if you know how instead of delete, when I press the button a value in the table changes. For example when click delete btn then value "OK" in table change to "DELETED".
The code work right for the specific id that put in delete.php file.
I'm not interested in database security I just want to find a way to make it work.
index.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "userform";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, email, code, status, lname, checkin, checkout, mnumber, totalprice, rescode FROM usertable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '
<table>
<tr>
<td>Fullname</td>
<td>', $row['name'] . $row['lname'], '</td>
</tr>
<br>
<tr>
<td>Email address</td>
<td>', $row['email'], '</td>
</tr>
<br>
<tr>
<td>Reservation ID</td>
<td>', $row['rescode'], '</td>
</tr>
<br>
<tr>
<td>Check-in</td>
<td>', $row['checkin'], '</td>
</tr>
<br>
<tr>
<td>Check-out</td>
<td>', $row['checkout'], '</td>
</tr>
<br>
<tr>
<td>Mobile number</td>
<td>', $row['mnumber'], '</td>
</tr>
<br>
<tr>
<td>Total price</td>
<td>', $row['totalprice'], '</td>
<td><a href="delete.php">Cancel</a></td>
</tr>
</table>';
}
} else {
echo "0 results";
}
$conn->close();
?>
<script>
delete.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "userform";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, email, code, status, lname, checkin, checkout, mnumber, totalprice, rescode FROM usertable";
$result = $conn->query($sql);
$sql = "DELETE FROM usertable WHERE id='10'";
if ($conn->query($sql) === TRUE) {
echo "Record deleted successfully";
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
?>