我试图在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"
));
答案 0 :(得分:0)
试试这个:
include_once('wp-includes/wp-db.php');
global $wpdb;
$wpdb->insert('design_information', ...
答案 1 :(得分:0)
这是一个wordpress功能,因此只有先前已定义全局$wpdb
才能调用它。
这意味着,在/ wp-content / ...文件夹中如果使用具有wp特定功能的脚本,则在使用wordpress核心编译之前它将无法工作。
因此,如果您正在使用独立脚本,那么它将无法正常工作。如果你想使用wordpress功能,那么你需要加载wordpress
如果您正在使用主题或插件,那么下面应该可以使用
global $wpdb;
$wpdb->insert();
...或按$ GLOBALS ...
访问它$GLOBALS['wpdb']->insert();