简体   繁体   English

致命错误在非对象上调用成员函数insert()

[英]Fatal error Call to a member function insert() on a non-object

I am trying to insert data using ajax in WordPress.But I am getting error below is my code in the file which I have called using ajax: 我试图在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"
               ));   

Um, it's weird, maybe the php thinks that variable hasn't been declared or is not an instance: 嗯,这很奇怪,也许php认为尚未声明变量或不是实例:

Try this: 尝试这个:

include_once('wp-includes/wp-db.php');

global $wpdb;
$wpdb->insert('design_information',  ...

It is a wordpress feature, so the global $wpdb can be called only if it has been defined previously. 这是一个wordpress功能,因此只有在先前定义了全局$wpdb下,才能调用它。

This means, inside the /wp-content/... folder if you use a script with wp specific features it won't work until it is compiled with wordpress core. 这意味着,在/ wp-content / ...文件夹中,如果您使用具有wp特定功能的脚本,则在使用wordpress core编译之前,该脚本将不起作用。

So, if you are working on standalone script than it will not work. 因此,如果您正在使用独立脚本,则它将无法正常工作。 if you want to use wordpress function then you need to load wordpress 如果您想使用wordpress功能,那么您需要加载wordpress

if you are working in theme or plugin then below should work 如果您正在主题或插件中工作,那么下面应该可以工作

global $wpdb;
$wpdb->insert();

… or access it per $GLOBALS … …或每$ GLOBALS访问一次…

$GLOBALS['wpdb']->insert();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object PHP:致命错误:在非对象上调用成员函数insert() - PHP: Fatal error: Call to a member function insert() on a non-object 致命错误:当它是一个对象时,调用非对象上的成员函数 - Fatal Error: Call to member function on non-object when it is an object 致命错误:在非对象错误上调用成员函数prepare() - Fatal error: Call to a member function prepare() on a non-object ERROR 致命错误:在非对象错误上调用成员函数 query() - Fatal error: Call to a member function query() on a non-object Error Magento:致命错误:在非对象上调用成员函数 getMethodInstance() - Magento : Fatal error: Call to a member function getMethodInstance() on a non-object CakePHP致命错误调用非对象上的成员函数schema() - CakePHP Fatal Error Call to a member function schema() on a non-object 致命错误:在非对象上调用成员函数 getElementsByTagName() - Fatal error: Call to a member function getElementsByTagName() on a non-object 致命错误:在非对象上调用成员函数toHtml() - Fatal error: Call to a member function toHtml() on a non-object 致命错误:在Codeigniter中的非对象上调用成员函数result() - Fatal error: Call to a member function result() on a non-object in Codeigniter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM