[英]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.