Whats wrong with this string

Discussion in 'Programming' started by mumfry, Nov 6, 2011.

  1. #1
    hey yall

    i am trying to pass a string into mysql but i cannot get any results even though there are results in the database with that query string as its title
    this is an example of what it looks like

    test text, text 'movies and videos,' more text

    i tried to use mysql_real_escape but even that didn't help

    whats getting in the way there

    any help would be greatly appreciated

    thanks
     
    mumfry, Nov 6, 2011 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    can you paste the whole query

    are you searching for text

    also paste one record that contain that text
    Regards

    Alex
     
    kmap, Nov 6, 2011 IP
  3. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    the query is

    @mysql_query("SELECT title,id FROM videos WHERE title like \"test text, text 'movies and videos,' more text\" ");

    and the record that contain that text is the same as the string
     
    mumfry, Nov 6, 2011 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    @mysql_query("SELECT title,id FROM videos WHERE title like \"test text, text \'movies and videos,\' more text\" ");

    it shd work

    Regards

    Alex
     
    Last edited: Nov 6, 2011
    kmap, Nov 6, 2011 IP
  5. gtownfunk

    gtownfunk Member

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    41
    #5
    Well, first off, you're using the LIKE operator when that is not how it is supposed to be used. If you're doing an exact string match, just use = (equals). LIKE is used for wildcard and sometimes regular expression matches. Second, you're escaping out the single ticks when they don't need to be escaped. The reason you escape the " quotes is to appease the PHP parser itself. "SELECt ....... "); You escape because you're putting quote marks in the query itself, \" escapes down to ". If you want escaped single tick marks inside that string, then you need to double escape them. You need your string to include \\'movies and videos,\\'. That way when it is passed to mysql_query() it actually still has the backslashes. You're escaping the backslashes the first time, not the single ticks.. and you'd be letting mysql handle escaped single ticks.

    I really suggest putting this string into a variable first and printing out the value of that variable. I think it will clarify what is going on and help you apply what may seem confusing about the escaping stuff I mentioned.
     
    gtownfunk, Nov 6, 2011 IP
  6. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #6
    kool
    thanks alot for that info my friend
     
    mumfry, Nov 6, 2011 IP