user2629119
user2629119

Reputation: 11

How to delete record from two or more tables

I have two tables resume_update and wp_rsjp_submissions

When I do a union of both tables I can fetch the records successfully but delete is not working. I have this query

<?php
    include('wp-blog-header.php');

    if($_POST['id']) { 
      $id=$_POST['id'];
      //echo($id); enter code here
      //$sql = "delete from user where id='$id'";`enter code here`global $wpdb;

      $row = $wpdb->get_row("delete from wp_rsjp_submissions, resume_update using wp_rsjp_submissions, resume_update where id='$id'");
    }
?>

Upvotes: 0

Views: 346

Answers (2)

Gogol
Gogol

Reputation: 3070

Use the following code instead.

<?php
    include('wp-blog-header.php');

    if($_POST['id']) { 
      $id=$_POST['id'];
      //echo($id); enter code here
      //$sql = "delete from user where id='$id'";`enter code here`global $wpdb;
      $sql = $wpdb->prepare("delete from wp_rsjp_submissions, resume_update using wp_rsjp_submissions, resume_update where id=%d" , array($id));

      $return = $wpdb->query($sql);
    }
?>

Also be sure to test your sql directly in mysql. I do not think this sql would work anyway.

Upvotes: 0

pmandell
pmandell

Reputation: 4328

In the official documentation for $wpdb seen here, you will see that get_row() is used to return a row.

To retrieve an entire row from a query, use get_row.

If you want to delete, you can use $wpdb->delete() or $wpdb->query().

Upvotes: 2

Related Questions