Title: Unexpected token
Last modified: August 31, 2016

---

# Unexpected token

 *  Resolved [DDT](https://wordpress.org/support/users/ddt/)
 * (@ddt)
 * [10 years ago](https://wordpress.org/support/topic/unexpected-token-8/)
 * Hi,
 * I have a fresh clean WP install with the latest WPCF7 and it works ok. But when
   I add a
    `add_action("wpcf7_before_send_mail", "add_to_database");`
 * WPCF7 is stuck with the spinning icon. It gives the following error
    `<div class
   ="ajax-error">Unexpected token < </div>`
 * My function add_to_database seems to work correctly as every item is saved in
   the table as expected.
 * How can I fix the unexpected token issue???
 * [edit] i enabled debugging and I see get this message:
    [22-Mar-2016 08:57:38
   UTC] PHP Warning: mysqli_real_escape_string() expects parameter 2 to be string,
   array given in /Applications/XAMPP/xamppfiles/htdocs/mydomain.com/wp-includes/
   wp-db.php on line 1127
 * IN my function I have
    `$result = $wpdb->query($wpdb->prepare("INSERT INTO ......`
 * Regards
 * [https://wordpress.org/plugins/contact-form-7/](https://wordpress.org/plugins/contact-form-7/)

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

 *  Thread Starter [DDT](https://wordpress.org/support/users/ddt/)
 * (@ddt)
 * [10 years ago](https://wordpress.org/support/topic/unexpected-token-8/#post-7196110)
 * i have rewritten funciton add_to_database with
 *     ```
       $result = $wpdb->insert("custom_table", array(
                   "approved" => NULL,
       ```
   
 *  Thread Starter [DDT](https://wordpress.org/support/users/ddt/)
 * (@ddt)
 * [10 years ago](https://wordpress.org/support/topic/unexpected-token-8/#post-7196151)
 * I also see
 * >  <div class=”ajax-error”>JSON.parse: unexpected character at line 1 column 
   > 1 of the JSON data</div>
 * Where/how can I see more information about JSON.parse: unexpected character at
   line 1 column 1 of the JSON data??
 * I am using firefox+firebug but can’t seem to get more information
 * ps: I already disabled all plugins and turn on theme twentyfiftheen
 *  Thread Starter [DDT](https://wordpress.org/support/users/ddt/)
 * (@ddt)
 * [10 years ago](https://wordpress.org/support/topic/unexpected-token-8/#post-7196171)
 * ok I narrowed it down to the following this CF7 shortcode
    `[checkbox* free-payed
   id:free-payed class:free-payed label_first exclusive "Free" "Payed" "Friends"]`
 * seems not to be working correctly.
 *     ```
       $submission = WPCF7_Submission::get_instance();
               if ($submission) {
                   $posted_data = $submission->get_posted_data();
        $free_payed = $posted_data["free-payed"];
       }
       ```
   
 * but if I set
    $free_payed = ‘test’; the query works correctly
 *  Thread Starter [DDT](https://wordpress.org/support/users/ddt/)
 * (@ddt)
 * [10 years ago](https://wordpress.org/support/topic/unexpected-token-8/#post-7196175)
 * Ok, finally found a solution I had to add [0] as checkbox form field are seen
   as array’s
 * `$free_payed = $posted_data["free-payed"][0];`

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

The topic ‘Unexpected token’ is closed to new replies.

 * ![](https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255)
 * [Contact Form 7](https://wordpress.org/plugins/contact-form-7/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contact-form-7/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contact-form-7/)
 * [Active Topics](https://wordpress.org/support/plugin/contact-form-7/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contact-form-7/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contact-form-7/reviews/)

## Tags

 * [Unexpected](https://wordpress.org/support/topic-tag/unexpected/)

 * 4 replies
 * 1 participant
 * Last reply from: [DDT](https://wordpress.org/support/users/ddt/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/unexpected-token-8/#post-7196175)
 * Status: resolved