[英]Fatal error Call to a member function insert() on a non-object
我試圖在WordPress中使用Ajax插入數據,但是我收到以下錯誤,這是我使用Ajax調用的文件中的代碼:
global $wpdb;
$wpdb->insert('design_information',
array(
'layout' => $_SESSION['layout'],
'language' => $_SESSION['briefform_language'],
'logo_name' => $_SESSION['briefform_businessName_validation'] ,
'org_description' => $_SESSION['briefform_businessPurpose'],
'bussiness_industry' => $_SESSION['briefform_businessIndustry'] ,
'slogan_logo' => $_SESSION['briefform_slogan'],
'payment' => $_SESSION['price'],
'others' => $_SESSION['briefform_comments'],
'fullname' => $_POST['paymentform_contactDetails_fullName'] ,
'company_name' => $_POST['paymentform_contactDetails_companyName'],
'coutry_code' => $_POST['paymentform_contactDetails_phoneCountry'] ,
'payment_status' => 'pending',
'color_picker' => $newValue1,
'phone_no' => $_POST['paymentform_contactDetails_phoneNumber'],
'address1' => $_POST['paymentform_billingDetails_address1'] ,
'address2' => $_POST['paymentform_billingDetails_address2'] ,
'city' => $_POST['paymentform_billingDetails_city'],
'zip' => $_POST['paymentform_billingDetails_zip'],
'state' => $_POST['paymentform_billingDetails_state'],
'country' => $_POST['paymentform_billingDetails_country'],
'design' => $newValue,
'slider' => $slider_value,
'Website Address' => $_SESSION['website address'],
'style' => $_SESSION['style'],
'like' => $_SESSION['like'],
'file' => $_SESSION['file'],
'email' => $_SESSION['email'],
'order_status' => "pending"
));
嗯,這很奇怪,也許php認為尚未聲明變量或不是實例:
嘗試這個:
include_once('wp-includes/wp-db.php');
global $wpdb;
$wpdb->insert('design_information', ...
這是一個wordpress功能,因此只有在先前定義了全局$wpdb
下,才能調用它。
這意味着,在/ wp-content / ...文件夾中,如果您使用具有wp特定功能的腳本,則在使用wordpress core編譯之前,該腳本將不起作用。
因此,如果您正在使用獨立腳本,則它將無法正常工作。 如果您想使用wordpress功能,那么您需要加載wordpress
如果您正在主題或插件中工作,那么下面應該可以工作
global $wpdb;
$wpdb->insert();
…或每$ GLOBALS訪問一次…
$GLOBALS['wpdb']->insert();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.