我正在将数据插入 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);
- 1 回答
- 0 关注
- 91 浏览
添加回答
举报
0/150
提交
取消