I am building a custom plugin for my WordPress site.
I made a php file called "checkrank" that obtains data from a custom table named "cranking".
$uid = $GET['id'];
function checkExists($id){
global $wpdb;
$table_name = $wpdb->prefix . 'cranking';
$exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %d" ) );
$error = $wpdb->print_error();
if(count($exists) > 0){
echo 'Exists!';
} else {
echo 'Does not exist!';
}
return $error;
}
checkExists($uid);
The code is just to check whether the cranking table has the user with the provided ID.
The problem is, whenever i run this php file, i get this error :
PHP Fatal error: Call to a member function
get_row()
on a non-object
Where am I at fault here?
I think $wbdp
is not initiated.