I'm making an admin plugin on my wordpress site. Im trying to add some delete function on my table row. my table is inside a foreach loop
$edteams = $wpdb->get_results(" //some sql query ");
foreach ($edteams as $row) {
echo "<tr><form class='form' action='' method='post'>";
echo "<td>$row->team_id</td>";
echo "<td>$row->team_name</td>";
echo "<td><input class='input' type='text' name='won' value='$row->games_won'> </td>";
echo "<td><input class='input' type='text' name='lost' value='$row->games_lost'> </td>";
echo "<td><input class='input' type='text' name='pct' value='$row->game_pct'></td>";
echo "<td><input class='input' type='text' name='streak' value='$row->winning_streak'></td>";
echo "<td><button class='btn btn-default' name='update'><span class='glyphicon glyphicon glyphicon-edit'></span></button>
<button class='btn btn-default' name='delete' value='$row->team_id'><span class='glyphicon glyphicon-trash'></span></button></td>";
echo "</tr>";
echo "<input type='hidden' id='team_id' value='$row->team_id'/>";
}
and here's my code for delete
if(isset($_POST['delete']))
{
echo "<script>alert('Your account is now deleted'); </script>";
$id = $wpdb->get_results("SELECT a.team_id, a.team_name, a.program_id ,b.games_won, b.games_lost, b.game_pct, b.winning_streak
FROM program_teams as a
INNER JOIN program_team_standings as b
ON a.team_id=b.team_id");
foreach ($id as $row) {
echo $id = $row->team_id;
}
echo "<script>alert('Your account is now deleted'); </script>";
$wpdb->delete( 'program_teams', array( 'team_id' => $id ) );
$wpdb->delete( 'program_team_standings', array( 'team_id' => $id ));
this code is not working when I click the delete button, its only redirecting on my admin page like nothing happened.