我正在將數據插入 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 關注
- 108 瀏覽
添加回答
舉報
0/150
提交
取消