$wpdb Fatal error
-
I’m tring to write a plugin and I’m having trouble using the database. I’m doing the following:
code
require_once ‘../wp-config.php’;
$title = ‘Magic Decks’;
$this_file = ‘magic-decks.php’;
$tablemagiccards = $table_prefix.’magiccards’;
$tablemagicdecks = $table_prefix.’magicdecks’;
function ensure_card($str) {
$sql = “SELECT card_name FROM $tablemagiccards WHERE card_name = $str”;
$cards = $wpdb->get_results($sql);
if ($cards) {
foreach($cards as $card){
$card->card_name = stripslashes($card->card_name);
echo $card->card_name.”<br/>”;
}
}else{
echo “$str not in database<br/>”;
}
}
code
From the plugin I’m tring to learn from (recent-links) this seems like it should work but I’m getting the following error:
Fatal error: Call to a member function get_results() on a non-object in C:\apachefriends\xampp\htdocs\moxy\wp-admin\magic-decks.php on line 12
What is it that I missed?
- The topic ‘$wpdb Fatal error’ is closed to new replies.