I have a users.php
file where I store all the functions. I want to create a remove button to remove any of the listed employees under a certain manager.
Here is my view of members function:
public function view_team($username) {
$query = $this->db->prepare("SELECT * FROM `users` WHERE `manager`= ? ORDER BY `lastname` ASC ");
$query->bindValue(1, $username);
$i = 0;
try{
$query->execute();
foreach ($query as $row) {
$removable=$row['id'];
print $i+1 .') '.$row['lastname'].' '.$row['firstname'].', Department: '. $row['department'] .', Band: '.$row['band'].' | '; ?>
Promote <img src="img/promote.png" alt="Promote employee"> | <!-- promote user -->
Edit <img src="img/edit.png" alt="Edit employee"> | <!-- edit user -->
<a href ="#" onclick="$users->remove($removable)">
Remove <img src="img/remove.png" alt="Remove employee"></a> <!-- remove user -->
<?php print '<br>';
$i++;
}
$this->queryResult = $query->fetch();
} catch(PDOException $e){
die($e->getMessage());
}
}
Here is the remove function:
public function remove($username) {
$query=$this->db->prepare("DELETE from `users` WHERE `id`=?");
$query->bindValue(1,$removable);
try{
$query->execute();
} catch (PDOException $e){
die($e->getMessage());
}
}
This is how I'm viewing the users:
<?php
$usr = $firstname ." ". $lastname;
$users->view_team($usr);
?>
I think I need to create an onclick()
function to work only when Remove button is pressed.