提交按钮后运行SQL

时间:2019-03-06 09:38:31

标签: wordpress

单击提交按钮但似乎操作不正确时,我试图使用WP SQL删除某些表/行。什么地方出了错?谢谢!

function delete_commands()
{
  include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php' );
  global $wpdb;
  ?>

  <form method="POST">
   <input class="btn" style="float:none;" type="submit"  name="delete" value="Delete all orders"  />
 </form>

  <?php
  if (isset($_POST['delete'])) {

        $table_name = $wpdb->prefix;

        $wpdb->query( $wpdb->prepare( "DELETE FROM {$table_name}_erp_ac_transactions WHERE ID = 12" ) );

    }
}

1 个答案:

答案 0 :(得分:0)

您必须在$之前使用单个wpdb->query,像这样解决查询问题:

$wpdb->query($wpdb->prepare(
    "DELETE FROM {$table_name}_erp_ac_transactions WHERE ID = %d", 12) );