Jump to content

how to comment out an apostrophy in an sql statement


paul2463

Recommended Posts

Hello everyone, I am sorry if this question has been asked a million times, but this is the first time I have come across this problem.

I have the end part of a  sql query that is being passed across pages( form a "table filter" type function)

it turns up looking like this
[code]
WHERE products.nameProd = \'3\' TUDOR\'
[/code]
mysql needs it to look like this
[code]
WHERE products.nameProd = '3\' TUDOR'
[/code]
I could always ask that entries in feet dont use the ' , but use "feet" instead, but it would be nicer to be able to remove the first and last "\" but leave the middle one intact. I have a pattern which strips out all the "\" but that obviously brings out mysql errors because it needs the middle one, any help gratefully recieved.
thanks for that and it works, to an extent.. I have tried using addslashes but the problem is that i need the two apostophes either side of the string '3'TUDOR' to remain as apostophes, but I need the middlw one slashed out. I have written a couple of functions for myself, as I know the itinerant apostrophe will always come after a number like 4'6 or 3' table etc etc I wrote a function that iterated along the string and if there were any apostrophes following directly behind a number it split the string added a "\" and the rebuilt the string. works for me

thanks anyway
The easier and more 'fool proof' method is mysql_real_escape_string() because addslashes() will add slashes to things that mysql doesn't necessarily need 'slashed'.

Plus, mysql_real_escpe_string() doesn't require you to use stripslashes() at the extraction point.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.