Results 1 to 11 of 11
  1. #1
    Join Date
    Aug 2003
    Location
    Walsall - UK
    Posts
    177

    PHP/mySQL slashing causing problems searching...

    Hey guys...

    I have entries in my mySQL database that are slashed, e.g: Nick\\'s Cars

    But the problem is when I come to call it from the database without a slash like this: Nick\'s Cars

    I addslashes before the query is carried out:

    PHP Code:
    $company_name=addslashes($company_name);

    $query="SELECT * FROM tod_company_information WHERE company_name='$company_name' ORDER BY $sort ASC";
    $result=mysql_query($query); 
    But it still doesn't return anything.... I've tried it with a field that doesn't have to be slashed... it works fine..

    Any ideas?

    Thanks in advance

    crE
    <<< Please see Forum Guidelines for signature setup. >>>

  2. #2
    Join Date
    Aug 2003
    Location
    Walsall - UK
    Posts
    177
    Ok, I just realised it was backslashed anyway without me needing to addslashes... But it still didn't give me a result!
    <<< Please see Forum Guidelines for signature setup. >>>

  3. #3
    Join Date
    Jul 2002
    Location
    UK
    Posts
    2,027
    echo $query;

    paste what it says.

    try pasting the output and manually running it on the database and see what it says (may be an error)
    Gone.

  4. #4
    Join Date
    Aug 2003
    Location
    Walsall - UK
    Posts
    177
    This is the query as it stands:

    PHP Code:
    SELECT FROM tod_company_information WHERE company_name="Nick\\\\'s Cars" ORDER BY company_name ASC 
    I tried doing the query in php my admin and it doesnt appear to be giving my any results... hmph

    crE
    <<< Please see Forum Guidelines for signature setup. >>>

  5. #5
    Join Date
    Jul 2002
    Location
    UK
    Posts
    2,027
    try making it so it's:

    PHP Code:
    SELECT FROM tod_company_information WHERE company_name='Nick\'s Cars' ORDER BY company_name ASC 
    Gone.

  6. #6
    Join Date
    Aug 2003
    Location
    Walsall - UK
    Posts
    177
    I tried using double and single quotes - but neither work!

    crE
    <<< Please see Forum Guidelines for signature setup. >>>

  7. #7
    you need to escape the /'s...

  8. #8
    there should be a function for this on the php website,

  9. #9
    sorry for all the posts, had to post 5 posts before i could post a url to another site

    http://us4.php.net/manual/en/function.addslashes.php

    the above should be really helpful,

  10. #10
    Join Date
    Aug 2003
    Location
    Walsall - UK
    Posts
    177
    I looked on the link and used this "urlencode" syntax.. it works good! Thanks acewebi!! You tha man

    crE
    <<< Please see Forum Guidelines for signature setup. >>>

  11. #11
    Join Date
    Feb 2004
    Posts
    772
    Hi,

    Whenever you are using slash operator you have to make it execute in your script by escaping that operator. So use backslash before the slash operator to make it print.

    Regards,

    Bright

Posting Permissions

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