Title: WP_DEBUG Message: &quot;Error in SQL syntax&quot; &#8212; Potential Fix
Last modified: August 21, 2016

---

# WP_DEBUG Message: "Error in SQL syntax" — Potential Fix

 *  Resolved [Phil](https://wordpress.org/support/users/philnelsonweb/)
 * (@philnelsonweb)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/wp_debug-message-error-in-sql-syntax-potential-fix/)
 * First, my sincere thanks for your fantastic plugin!
 * **Error Messages**
    `SELECT location_status FROM wp_em_locations WHERE location_id
   =` `UPDATE wp_em_locations SET location_status=NULL WHERE location_id=`
 * **Steps to Reproduce**
    1. in wp-config.php: `define('WP_DEBUG', true);`
    2. begin creating new event in admin (e.g., at site.com/wp-admin/post-new.php?post_type
       =event )
    3. complete title and date fields
    4. leave location fields blank, and do NOT check box for “This event does not have
       a physical location
    5. click ‘publish’ or ‘save draft’
 * With the required location fields left blank, we would expect a validation error,
   but with WP_DEBUG turned on, the SQL errors above show up first. No location_id
   is being passed to the SQL query.
 * **Potential Fix — Part 1**
    The plugin authors will see a bigger picture than
   I see, but here’s a possible start at addressing the issue.
 * When saving an event, EM calls `$EM_Event->save_meta()`, which begins by validating/
   saving the location fields. Using the steps above, this location validation/save
   fails, and I think EM intends to respond by setting the event post_status to 
   draft, because perhaps it’s better to not publish the event if its location info
   is missing.
 * So, from within `$EM_Event->save_meta()`, EM calls `$this->get_location()->set_status(
   null);`. The null parameter sets the post to draft status, but the crucial point
   is that it is dealing with the **LOCATION** post ($EM_Location object). I think
   perhaps `$EM_Event->save_meta()` should have called `$this->set_status(null)`,
   which would have set the **EVENT** post ($EM_Event object) to draft. It would
   also avoid the location_id SQL error.
 * **Potential Fix — Part 2**
    Assume we’ve made the switch to using `$EM_Event-
   >set_status()`. A couple of its final tasks query the EM_EVENTS_TABLE using `
   $EM_Event->event_id`. The problem is that event_id is still null at this point,
   so we get an SQL error similar to the one above. A value for `$EM_Event->event_id`
   won’t be loaded in till later in `$EM_Event->set_status()` where it calls `$wpdb-
   >insert(EM_EVENTS_TABLE, $event_array)`.
 * Of course, one approach to preventing the SQL error that comes from using “WHERE
   event_id=[null]” would be to only run the SQL queries on the condition that event_id
   is not null. For example, this code from within $EM_Event->set_status() …
 *     ```
       $this->get_previous_status();
       $result = $wpdb->query("UPDATE ".EM_EVENTS_TABLE." SET event_status=$set_status, event_slug='{$this->post_name}' WHERE event_id=".$this->event_id);
       $this->get_status(); //reload status
       ```
   
 * … could be replaced with this …
 *     ```
       if ( null !== $this->event_id ) {
         $this->get_previous_status();
         $result = $wpdb->query("UPDATE ".EM_EVENTS_TABLE." SET event_status=$set_status, event_slug='{$this->post_name}' WHERE event_id=".$this->event_id);
         $this->get_status(); //reload status
       }
       else
         $result = true;
       ```
   
 * If appropriate, these changes may address issues such as [1](http://wordpress.org/support/topic/you-have-an-error-in-your-sql-syntax-6),
   [2](http://wpml.org/forums/topic/wpml-with-event-manager-creating-new-event/),
   [3](http://wordpress.org/support/topic/events-manager-sql-syntax-error-with-location).
   With only a quick look, I don’t see it possible that `$EM_Location->set_status()`
   could ever run without a value for location_id, so it does not appear necessary
   to also check `if ( null !== $this->location_id )` from within `$EM_Location-
   >set_status()`.
 * **My Setup**
    I set up a fresh dev site to test: WP 3.5.2 (WP_DEBUG turned on;
   not MultiSite), Twenty Twelve 1.1, Events Manager 5.4.4, PHP 5.3.1, MySQL 5.1.44,
   no other plugins.
 * [http://wordpress.org/extend/plugins/events-manager/](http://wordpress.org/extend/plugins/events-manager/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [agelonwl](https://wordpress.org/support/users/angelonwl/)
 * (@angelonwl)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/wp_debug-message-error-in-sql-syntax-potential-fix/#post-3932233)
 * I get this too, I’ve let Marcus know about it. should get fixed soon.
 *  Plugin Author [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * (@netweblogic)
 * [12 years, 8 months ago](https://wordpress.org/support/topic/wp_debug-message-error-in-sql-syntax-potential-fix/#post-3932277)
 * I’ve asked angelo to show me the reproduction on his site, as I don’t get this
   locally.
 * Thanks for all the details, will look into this and get back to you.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP_DEBUG Message: "Error in SQL syntax" — Potential Fix’ is closed to
new replies.

 * ![](https://ps.w.org/events-manager/assets/icon-256x256.png?rev=1039078)
 * [Events Manager - Calendar, Bookings, Tickets, and more!](https://wordpress.org/plugins/events-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/events-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/events-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/events-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/events-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/events-manager/reviews/)

## Tags

 * [create event](https://wordpress.org/support/topic-tag/create-event/)
 * [WordPress database error](https://wordpress.org/support/topic-tag/wordpress-database-error/)

 * 2 replies
 * 3 participants
 * Last reply from: [Marcus (aka @msykes)](https://wordpress.org/support/users/netweblogic/)
 * Last activity: [12 years, 8 months ago](https://wordpress.org/support/topic/wp_debug-message-error-in-sql-syntax-potential-fix/#post-3932277)
 * Status: resolved