Here I created a custom profile page based on the current logged user to check only his own data inserted in a custom database.

You can see that in every row, I added a button "Delete" missing the appropriate code.

Everything is working well except that part where I want to add a function to Delete the record. Maybe $wpdb->delete() solves my problem.

This is my code:

if ( is_user_logged_in() ) {
global $wpdb;
$current_user = wp_get_current_user();
$username = $current_user->user_login;
$reservations = $wpdb->get_results($wpdb->prepare("SELECT * FROM 
SaveContactForm7_1 WHERE user = %s", $username));

echo "<div align='center'>";
echo "<table class='responsive-table'>";
echo "<caption>Liste des r&eacute;servations</caption>";
echo "<thead>";
echo "<tr>";
echo "<th scope='col'>Nom</th>";
echo "<th scope='col'>ID</th>";
echo "<th scope='col'>Qualit&eacute;</th>";
echo "<th scope='col'>Arriv&eacute;e</th>";
echo "<th scope='col'>Num Vol</th>";
echo "<th scope='col'>H. Att</th>";
echo "<th scope='col'>Prov</th>";
echo "<th scope='col'>Depart</th>";
echo "<th scope='col'>Num Vol</th>";
echo "<th scope='col'>H. Decl</th>";
echo "<th scope='col'>Dest</th>";
echo "<th scope='col'>H&ocirc;tel</th>";
echo "<th scope='col'>Chambre</th>";
echo "<th scope='col'>Total</th>";
echo "<th scope='col'>Modifier</th>";
echo "<th scope='col'>Effacer</th>";
echo "</tr>";
echo "</thead>";
foreach($reservations as $reservation){
echo "<tbody>";
echo "<tr>";
echo "<th  scope='row'>".$reservation->nom."</th>";
echo "<td data-title='ID'>".$reservation->user."</td>";
echo "<td data-title='Qualit&eacute;'>".$reservation->qualite."</td>";
echo "<td data-title='Arriv&eacute;e'>".$reservation->datearrivee."</td>";
echo "<td data-title='N&#176; Vol'>".$reservation->num_vol_arrivee."</td>";
echo "<td data-title='Atterrissage'>".$reservation->heure_atterrissage."
echo "<td data-title='Provenance'>".$reservation->provenance."</td>";
echo "<td data-title='D&eacute;part'>".$reservation->datedepart."</td>";
echo "<td data-title='N&#176; VOL'>".$reservation->num_vol_depart."</td>";
echo "<td data-title='D&eacute;collage'>".$reservation->heure_decollage."
echo "<td data-title='D&eacute;stination'>".$reservation->destination."
echo "<td data-title='Choix'>".$reservation->choix."</td>";
echo "<td data-title='Chambre'>".$reservation->typech."</td>";
echo "<td data-title='Prix Total' data-type='currency'>".$reservation-

And here the "Delete" part:

echo "<td align='center'>

<***I need the code here "input" or "a href" ***><img class='icon' width='16' height='16'
src='../remove-icon.png' alt='Delete' title='Delete'></a>
echo "</tr>";
echo "</tbody>";
echo "</table>";
echo "</div>";
  • Are you asking how to delete a row using MySQL?
    – kero
    Sep 26, 2017 at 12:13
  • The delete part is not the end of the work need it to make it work. You can choose to make this an Ajax request to notify the server of an action and perform whatever action you want to do. Another approach will be to send a submit request to make the deletion and reload the form. Both ways have + and -. Sep 26, 2017 at 12:43

2 Answers 2


Yes, you can use wpdb to delete the record in the custom table. Something like this in the wordpress function.

require_once ('../../../../wp-load.php');

if (!empty($_POST['id'])) {

  global $wpdb;

  $id = $_POST['id'];
  $wpdb->delete( $table, array( 'id' => $id ) );

  • That works with some modifications 🖒 Oct 3, 2017 at 20:03
  • client side -> user click delete button/link

  • AJAX ->send this action from client side to server side to run php function delete corresponding raw from database .

  • server side->function to delete raw from database $wpdb->delete()

  • AJAX success ->hide this raw from client page and update this only part of page

check that link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.