Grow your CSS skills. Land your dream job.

WordPress Custom Form Error

  • # October 4, 2012 at 10:36 am

    I’m writing a plugin that posts data to the WordPress database.

    For the most part I have the basics working. I’m using this to check for duplicate entries.

    $duplicate =  $wpdb->get_results("SELECT * FROM wp_flr_locations WHERE location_name = '{$location_name}'");
    if (isset($_POST)) {
    if ($duplicate != '') {
    $wpdb->insert( 'wp_flr_locations', array( 'location_name' => $_POST ) );
    } else {
    echo'
    No Duplaicates Allowed
    ';
    }
    }

    This does prevent duplicate entries from being posted to the database. The problem I'm having is I want an error message to show if it is duplicate. The "else" doesn't seem to work.

    Any Ideas?

    # October 4, 2012 at 7:53 pm

    I would try changing your if statement to something like

    if(!empty($duplicate){

    }

    The point is that WordPress may still be sending data that the if statement as is won’t read correctly. From my experience, using empty() works better than using ” “;

    My “if” may be backwards, not an expert php programmer here.

    # October 4, 2012 at 9:14 pm

    Thanks I’ll give it a try.
    I’m not a php expert either if you couldn’t tell.:)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".