Special Characters in PHP

Discussion in 'Programming' started by shahgols, May 12, 2009.

  1. #1
    Hi everyone,

    I have a select statement that I am going to pass to MYSQL:

    q1 = "select * from company where company_name = '$company'";

    When $company has a special character, then the PHP code fails. For example, if $company is "Barnes & Noble", then it fails. How do I deal with this situation?

    Thanks in advance.
     
    shahgols, May 12, 2009 IP
  2. shahgols

    shahgols Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Shoot, should have posted this in the PHP forum. Sorry about that.
     
    shahgols, May 12, 2009 IP
  3. JohnUK

    JohnUK Peon

    Messages:
    178
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try q1 = mysql_query("select * from company where company_name = '".mysql_real_escape_string($company)."'");

    You can prob get rid of some of the speech marks. play around with it.
     
    JohnUK, May 12, 2009 IP
  4. shahgols

    shahgols Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks much! I'll take a look.
     
    shahgols, May 12, 2009 IP