【问题标题】:Showing Notice: Undefined property: wpdb::$insertid in D:\wamp\www\wordpress-4.7.1\wordpress\wp-includes\wp-db.php on line 684 [duplicate]显示注意事项:未定义的属性:D:\wamp\www\wordpress-4.7.1\wordpress\wp-includes\wp-db.php 中的 wpdb::$insertid 第 684 行 [重复]
【发布时间】:2018-09-27 04:45:27
【问题描述】:

我想获取最后插入的 id 以根据此 id 更新表。为此,我使用 $wpdb->insert_id 来获取最后插入的 id。但是得到这个问题 注意:未定义的属性:D:\wamp\www\wordpress-4.7.1\wordpress\wp-includes\wp-db.php 中的 wpdb::$insertid 在第 684 行

这是我的代码。有人请帮忙

$parent_id=$template_load_data['id'];
         $wpdb->insert( 'wp_rxl_templates', array(
                'template_name' => $_POST['template_name_custom'],
                'template_content' => $post_content,
                'created_date' => current_time( 'mysql' ),
                'status' => 'active',
                'default_template'=>'false',
                'parent_template_id'=>''.$parent_id.'',
            ));
            $result_id = $wpdb->insertid;
 $result_data = "select wp_rxl where status ='active' NOT (id = '$result_id')";

【问题讨论】:

  • 我是$wpdb->insert_id
  • 感谢您现在的工作。我还有一个疑问。如何根据此 id 更新表。场景是我需要将此行插入为活动的,而所有其他行期望最后插入的行需要处于非活动状态。
  • @Mittul 是的,我用过
  • "选择 wp_rxl where status ='active' NOT (id = '$result_id')";
  • 这样对吗?

标签: php mysql wordpress


【解决方案1】:

你写错了。检查以下:

您必须使用$wpdb->insert_id 而不是$wpdb->insertid

$parent_id=$template_load_data['id'];
         $wpdb->insert( 'wp_rxl_templates', array(
                'template_name' => $_POST['template_name_custom'],
                'template_content' => $post_content,
                'created_date' => current_time( 'mysql' ),
                'status' => 'active',
                'default_template'=>'false',
                'parent_template_id'=>''.$parent_id.'',
            ));
            $result_id = $wpdb->insert_id;
 $result_data = "select wp_rxl where status ='active' NOT (id = '$result_id')";

【讨论】:

  • 谢谢,现在可以正常使用了
  • 很好。将其标记为已接受并请投赞成票。很高兴能提供帮助。
  • 当然,我会的
猜你喜欢
  • 1970-01-01
  • 2014-05-29
  • 2017-04-08
  • 2015-12-24
  • 2023-01-08
  • 2016-10-09
  • 1970-01-01
  • 2015-07-12
  • 2023-01-19
相关资源
最近更新 更多