I have been trying for hours to simply call a table in a wordpress dbase through a .ajax post, and return the value I want, but I get this error on the returning page: "Call to a member function get_results() on a non object".
here is my php file:
<?php
global $wpdb;
if (isset($_POST['state'])) {
$results=$wpdb->get_results("SELECT DISTINCT make FROM cz_cars ORDER BY make ASC");
echo $results[0][0];
exit;
}
?>
Here is the jquery i am using:
jQuery(document).ready(function()
{
jQuery("#caryear").change(function()
{
jQuery.ajax(
{
type: "POST",
url: "wp-content/themes/storefront/includes/post-yearmakel.php",
data: ({ 'state' : jQuery("#caryear").val() }),
success: function(msg)
{
jQuery('#carmake').append('' + msg + '');
}
});
});
});
This code works fine when I comment out the database stuff in the php file, and just echo back a string. I have the php file with the other includes and it is being recognized by wordpress. No idea whats going on here...I thought having global $wpdb; would make this work!
Any ideas?