Web Hosting Talk







View Full Version : PHP/mySQL slashing causing problems searching...


crEA-tEch
03-07-2004, 11:42 AM
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:

$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

crEA-tEch
03-07-2004, 11:46 AM
Ok, I just realised it was backslashed anyway without me needing to addslashes... But it still didn't give me a result!

Informity
03-07-2004, 11:52 AM
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)

crEA-tEch
03-07-2004, 12:14 PM
This is the query as it stands:

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

Informity
03-07-2004, 12:28 PM
try making it so it's:


SELECT * FROM tod_company_information WHERE company_name='Nick\'s Cars' ORDER BY company_name ASC

crEA-tEch
03-07-2004, 12:34 PM
I tried using double and single quotes - but neither work!

crE

acewebi
03-07-2004, 08:34 PM
you need to escape the /'s...

acewebi
03-07-2004, 08:38 PM
there should be a function for this on the php website,

acewebi
03-07-2004, 08:42 PM
sorry for all the posts, had to post 5 posts before i could post a url to another site :mad:

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

the above should be really helpful,

crEA-tEch
03-09-2004, 03:45 PM
I looked on the link and used this "urlencode" syntax.. it works good! Thanks acewebi!! You tha man

crE

Brightadmin
03-15-2004, 09:39 AM
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:)