A
Anonymous
Guest
Hey everyone, I would like to delete a whole row from sql with php.
For that I would like to use the Button that is on each row. But i cant really figure it how to do, i tried to create a statement ($delete) but that doesnt work either
For that I would like to use the Button that is on each row. But i cant really figure it how to do, i tried to create a statement ($delete) but that doesnt work either
Code:
<head>
<title>Tables</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<?php
$server = 'localhost';
$user = 'root';
$password = '';
$db = 'bfi';
$connection = new mysqli($server, $user, $password, $db);
if ($connection->connect_error) {
echo $connection->connect_error;
}
$sql = "SELECT * FROM employees";
$result = $connection->query($sql);
$Delete = "DELETE FROM employees WHERE LastName='Fuller'";
echo '<table class="table table-dark table-hover">';
echo '<thead><tr>';
echo '<th>ID</th>';
echo '<th>LastName</th>';
echo '<th>FirstName</th>';
echo '<th>BDay</th>';
echo '<th>Delete</th';
echo '</tr></thead>';
while ($row = $result->fetch_object()) {
echo "<tr>";
echo "<td>" . $row->EmployeeID . "</td>";
echo "<td>" . $row->LastName . "</td>";
echo "<td>" . $row->FirstName . "</td>";
echo "<td>" . $row->BirthDate . "</td>";
echo "<td>" . "<a class='btn btn-danger' href='#'>Delete</a>" . "</td>";
echo '</tr>';
}
$connection->close();