简体   繁体   English

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

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

I get an error from using the function below: Call to a member function insert() on a non-object. 使用以下函数会出错:在非对象上调用成员函数insert()。 Please help! 请帮忙!

<?php 

$hostname = "dd";
$username = "cc";
$password = "aa";
$dbName = "bb";
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db("$dbName") or die( "Unable to select database");

subscribe($email, $firstname, $lastname, $company);

function subscribe($email, $first, $last, $company)
{
             global $wpdb;  
             $wpdb -> insert('aca11052015_subscribers', array(
            'First Name' => $first,
            'Last Name' => $last,
            'Company' => $company,
            'Email' => $email,
            'Date' => date("Y-m-d H:i:s")
        ));    
}

The $wpdb global has not been initiated as you are running via ajax and calling that file independently. $ wpdb全局尚未启动,因为您正在通过ajax运行并独立调用该文件。

Within the file that has that code if you add: 在具有该代码的文件中,如果您添加:

require_once('wp-load.php'); 

Make sure that it points to the correct path to that file (it should be in the root of your site) things should start working. 确保它指向该文件的正确路径(该路径应该在您网站的根目录中),然后一切开始起作用。

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

相关问题 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object 致命错误在非对象上调用成员函数insert() - Fatal error Call to a member function insert() on a non-object 致命错误在非对象PHP上调用成员函数login() - Fatal Error Call to a member function login() on a non-object PHP 致命错误:在非对象php上调用成员函数execute() - Fatal error: Call to a member function execute() on a non-object php PHP:致命错误:在非对象中调用成员函数appendChild() - PHP: Fatal error: Call to a member function appendChild() on a non-object in PHP致命错误:在非对象中调用成员函数getScore() - PHP Fatal error: Call to a member function getScore() on a non-object in php致命错误:在非对象上调用成员函数children() - php Fatal error: Call to a member function children() on a non-object PHP致命错误:在非对象中调用成员函数smileysboxrep() - PHP Fatal error: Call to a member function smileysboxrep() on a non-object in PHP致命错误:在非对象上调用成员函数hasAttribute() - PHP Fatal error: Call to a member function hasAttribute() on a non-object PHP 致命错误:在非对象上调用成员函数 row() - PHP Fatal error: Call to a member function row() on a non-object in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM