WordPress.org

Ready to get started?Download WordPress

Forums

Writing WordPress Plugins - Call to a member function on a non-object error (3 posts)

  1. Rhys Wynne
    Member
    Posted 7 years ago #

    I'm not quite sure whether I should post this here or in a dedicated PHP coding forum, nevertheless forgive me if you feel it is pointless.

    I am trying to write my own plugins in wordpress, and I started off by adding some functionality to a plugin already out there (the WPAds). I'm trying to write a couple of functions that track banner clicks.

    The easiest way I found was to create a wpads-bannerclick.php file which has an id passed into it. This file then looks at the database to update the amount of clicks the banner has recieved as well as forward the user on to the destination URL.

    The problem I am having is referencing the database. I recieve a " " error whenever I try and access the database.

    Below is my current code for wpads-bannerclick:

    <?php 
    
     	include_once( 'wpads-class.php' );
    	global $wpdb;
    	$id = $_GET["id"];
    	$sql = "SELECT * FROM ". $wpdb->prefix . "ads_banners WHERE banner_id = '" . $id;
    	$banners = $wpdb->get_results( $sql );
    ?>

    It just doesn't seem to like any sort of referencing with the database. Is there something I am doing blidingly obvious with my code that's wrong? Or is there some wordpress function or set of files I'm not referencing.

    Any further code you need to look at can be given. A lot of it is written by somebody else, as I said it's really for my own amusement/learning, but I would like to know what I'm doing wrong :)

  2. goodspeed1
    Member
    Posted 6 years ago #

    I get the same error. Anyone here can point us to the right direction?

  3. jrrl
    Member
    Posted 6 years ago #

    In the code you posted, you don't close the single-quotes around the id in your SQL. You need to add something like:

    . "'"

    to the line that builds the sql statement.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags