Finding strings containing special characters in a WHERE clause

Discussion in 'PHP' started by Darden12, Jul 13, 2009.

  1. #1
    Can someone tell me how to get the following database search to work? The special characters in the $find variable (especially the > and <) keep giving me parsing errors:

    $find="<?php include 'iv_inline.php' ?>";
    
    $result=mysql_query("SELECT * FROM Articles WHERE Article LIKE '%$find%'") or die(mysql_error());
     
    PHP:
    I've read dozens of suggestions online about how to get this to work and so far none of the solutions have worked for me. I've tried dealing with the < and > special characters by using htmlentities, add_slashes, mysql_real_escape_string, etc....

    and so far nothing works.

    To summarize: How can I search for strings using LIKE when the string contains < and >


    Thanks for any help.

    Brian
     
    Darden12, Jul 13, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    $result=mysql_query("
    SELECT *
    FROM Articles
    WHERE Article LIKE '%<%'
    AND Article LIKE '%>%'
    ") or die(mysql_error());
     
    jestep, Jul 13, 2009 IP
  3. Darden12

    Darden12 Well-Known Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Thanks. But is there no way to search for an entire phrase that contains < and >
    rather than just searching for < and > by theirselves?
     
    Darden12, Jul 13, 2009 IP