Untitled
unknown
plain_text
a month ago
1.9 kB
3
Indexable
fetch.php: <?php include 'config.php'; $result = $conn->query("SELECT * FROM employees ORDER BY id DESC"); if ($result->num_rows > 0) { echo "<table class='table table-bordered'> <thead> <tr> <th>ID</th> <th>Full Name</th> <th>Position</th> <th>Hours Worked</th> <th>Rate per Hour</th> <th>Total Salary</th> <th>Actions</th> </tr> </thead> <tbody>"; while ($row = $result->fetch_assoc()) { echo "<tr> <td>{$row['id']}</td> <td>{$row['first_name']} {$row['last_name']}</td> <td>{$row['position']}</td> <td>{$row['hours_worked']}</td> <td>{$row['rate_per_hour']}</td> <td>{$row['total_salary']}</td> <td> <button class='btn btn-warning btn-sm editBtn' data-id='{$row['id']}' data-first_name='{$row['first_name']}' data-last_name='{$row['last_name']}' data-position='{$row['position']}' data-hours_worked='{$row['hours_worked']}' data-rate_per_hour='{$row['rate_per_hour']}'>Edit</button> <button class='btn btn-danger btn-sm deleteBtn' data-id='{$row['id']}'>Delete</button> </td> </tr>"; } echo "</tbody></table>"; } else { echo "<p>No employees found.</p>"; } ?> delete.php: <?php include 'config.php'; if (isset($_POST['id'])) { $id = intval($_POST['id']); $sql = "DELETE FROM employees WHERE id=$id"; if ($conn->query($sql) === TRUE) { echo "Employee deleted successfully!"; } else { echo "Error: " . $conn->error; } } ?>
Editor is loading...
Leave a Comment