我正在將數(shù)據(jù)插入 WordPress 的數(shù)據(jù)庫中。我在網(wǎng)絡(luò)選項(xiàng)卡中收到錯(cuò)誤:致命錯(cuò)誤:未捕獲的錯(cuò)誤:在 null 上調(diào)用成員函數(shù) 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貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
希望能幫到你。在你的 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 關(guān)注
- 101 瀏覽
添加回答
舉報(bào)
0/150
提交
取消