I get an error from using the function below: Call to a member function insert() on a non-object.
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.
Within the file that has that code if you add:
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.