PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Special Character problem when importing entires into new table

  1. I am exporting the entry data into a table, trouble is, any entry that has an apostrophe in the name (O'Donnel) does not come thru. Error log showing name field as 'O'Connor'

    I assume that the apostrophe needs to be escaped - but I cannot figure how to do it. Would I do it in the hook in the functions.php file?:

    // Pulls gravity form entries into xml and outputs

    add_action('gform_after_submission_6', 'input_fields', 8, 4);
    function input_fields($entry, $form){
    global $wpdb;
    
        $promocode = $entry['7'];
        $conferenceid = $entry['6'];
        $conferencechoice = $entry['1'];
        $firstname = $entry['2.3'];
        $lastname = $entry['2.6'];
        $phone = $entry['3'];
        $email = $entry['4'];
        $optinternal = $entry['5.1'];
        $optexternal = $entry['5.2'];
    
      $SQL = "INSERT INTO fsleads ( userid, promocode, conferenceid, conferencechoice, firstname, lastname, phone, email, optinternal, optexternal, uploaded ) VALUES ( '', '$promocode', '$conferenceid', '$conferencechoice', '$firstname', '$lastname', '$phone', '$email', '$optinternal', '$optexternal' , 'N' )";
      $wpdb->query($SQL);
    Posted 11 years ago on Monday December 3, 2012 | Permalink
  2. This is an issue with your own code rather than the Gravity Forms export routine?

    To escape values before inserting them, if they may have apostrophes or single quotes, you can use the PHP function mysql_real_escape_string.

    http://php.net/manual/en/function.mysql-real-escape-string.php

    [php]
    $firstname = mysql_real_escape_string($entry['2.3']);
    $lastname = mysql_real_escape_string($entry['2.6']);

    You might need to do that with more fields, but that is basically how to do it. Not related to Gravity Forms at all, just PHP and MySQL.

    Posted 11 years ago on Monday December 3, 2012 | Permalink
  3. That's exactly it! Thank you so much. Perfect answer for what I was looking for.
    Thank you!

    Posted 11 years ago on Tuesday December 4, 2012 | Permalink
  4. You're welcome.

    Posted 11 years ago on Thursday December 6, 2012 | Permalink

This topic has been resolved and has been closed to new replies.