I have a plugin that reads data from WordPress database. I want the admin to be able to delete a record from the database using the data's ID. how do i do this... i have tried
if ($_GET) {
if ( isset( $_GET['in_delete'] ) ) {
global $wpdb;
$result = $wpdb->get_results( "SELECT * FROM bookings" );
foreach ( $result as $print ) {
$id = $print->id;
$del = $wpdb->delete( 'bookings', $id );
if ( $del ) {
echo "<script>
alert('record deleted');
</script>";
}
}
}
}
and my button is
<form action="" name="operations" method="get" >
<input type="button" name="in_delete" value="Delete" style="color:#fff; height:19px; width: 60px; font-size:10px; background-color: red;cursor: pointer;"><br>
</form>