The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

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 {
    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

    This reply has been reported for inappropriate content.

    I would try changing your if statement to something like



    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.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed