I am trying to delete records from my custom table but it does not delete anything.
Here is my code:
<?php
global $wpdb;
$retrieve_data = $wpdb->get_results( "SELECT * FROM wp_paypal" );
// some code to display here...
?>
<form method="post" enctype="multipart/form-data">
<td><input type="submit" name="delete" value="Delete" /></td>
</form>
<?php
$myid= $retrieved_data->id;
if (isset($_POST['delete'])) {
//global $wpdb;
$wpdb->query(
'DELETE FROM $wpdb->paypal
WHERE id = "'.$myid.'"
'
);
}
}
2 Answers
Try to use $wpdb->prefix
insted of $wpdb
in Delete query.
Example:
$wpdb->query(
'DELETE FROM '.$wpdb->prefix.'paypal
WHERE id = "'.$myid.'"'
);