为了账号安全,请及时绑定邮箱和手机立即绑定

致命错误:未捕获的错误:在 wordpress 中调用 null 上的成员函数 insert()

致命错误:未捕获的错误:在 wordpress 中调用 null 上的成员函数 insert()

PHP
牛魔王的故事 2022-05-27 10:06:34
我正在将数据插入 WordPress 的数据库中。我在网络选项卡中收到错误:致命错误:未捕获的错误:在 null 上调用成员函数 insert()这是我的逻辑<?php  global $wpdb;        // <--- making $wpdb as global  $wpdb->insert('contact',    array(      'name' => $_POST['c_name'],      'email' => $_POST['c_email'],      'phone' => $_POST['c_mobileno'],      'type_of_services' => $_POST['c_type_of_services'],      'message' => $_POST['c_message']    ),    array(      '%s',      '%s',      '%s',      '%s',      '%s',    )  );  // $wpdb->show_errors(); ?>jQuery(document).ready(function($) {  $('#contact_form').on('submit', function(e) {    e.preventDefault();    var form = $(this);    $.ajax({      url: "/process.php",      type: "post",      data: form.serialize(),                 dataType: "JSON",      success: function(response) {        alert("submited");      }    });  });     });
查看完整描述

1 回答

?
鸿蒙传说

TA贡献1865条经验 获得超7个赞

希望能帮到你。在你的 php 文件中添加:


define( 'BLOCK_LOAD', true );

require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' );

require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-includes/wp-db.php' );

$wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);


查看完整回答
反对 回复 2022-05-27
  • 1 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号