Results 1 to 3 of 3

Thread: Apostrophe Issue

  1. #1
    tylerkolden is offline Member
    Join Date
    Sep 2009
    Posts
    10

    Default Apostrophe Issue

    I am having an issue with names that have an apostrophe ( ‘ ) in them.
    I have the following query in a logic hook. The purpose is to get an email address from another module based on the first and last names. The email addresses are not stored in the email tables in sugarCRM.

    PHP Code:
        $first_name $bean->first_name;
        
    $last_name $bean->last_name;
        
    //$first_name = "Theresa";
        //$last_name = "O'Loughlin";
                            
        ///obtain email address///
        
    $query1 "select rolus_onmission.first_name, rolus_onmission.last_name, rolus_applications.email 
                        from rolus_onmission
                        join rolus_applications 
                        on
                        rolus_applications.first_name  = rolus_onmission.first_name
                                            and
                                            rolus_applications.last_name  = rolus_onmission.last_name
                        where 
                        rolus_applications.first_name = \"$first_name\"
                        and
                        rolus_applications.last_name  = \"$last_name\" " 
    ;
                        
    $results1 $bean->db->query($query1true);
                        
    $row1 $bean->db->fetchByAssoc($results1);
                        
    $applicant_email $row1['email']; 
    When this logic hook encounters names without an apostrophe, it works very well and properly provides the email address. However when the name contains and apostrophe, it fails.

    It is also very interesting that when the first and last names are not collected from the bean, but stated (currently commented out) the query works properly.

    Below is a copy of the query:

    Code:
    select rolus_onmission.first_name, rolus_onmission.last_name, rolus_applications.email from rolus_onmission join rolus_applications on rolus_applications.first_name = rolus_onmission.first_name and rolus_applications.last_name = rolus_onmission.last_name where rolus_applications.first_name = "Theresa" and rolus_applications.last_name = "O'Loughlin"
    It works at a mysql command line query but not through sugarcrm.

    Any help would be greatly appreciated.

    Tyler

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Apostrophe Issue

    Try this code:

    PHP Code:
    $first_name $bean->db->quote($first_name); 
    Do the same for other variables.

    Regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    tylerkolden is offline Member
    Join Date
    Sep 2009
    Posts
    10

    Default Re: Apostrophe Issue

    Amazing. It worked perfectly. I simply added your line of code for each variable and the SQL produced the proper result.


    PHP Code:
    $first_name $bean->first_name;
    $last_name $bean->last_name;  
    $query_first_name $bean->db->quote($first_name);  
    $query_last_name $bean->db->quote($last_name); 
    Thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 2010-03-30, 12:37 PM
  2. Apostrophe in RSS headline (2.5.0)
    By jpshea in forum Feature Requests
    Replies: 0
    Last Post: 2005-02-25, 06:09 AM
  3. Account Name w/Apostrophe
    By udannlin in forum Help
    Replies: 2
    Last Post: 2004-08-12, 04:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •