paul2463 Posted November 8, 2006 Share Posted November 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
sasa Posted November 8, 2006 Share Posted November 8, 2006 try[code]<?php$a = "it's best Mark's work";echo $a,"<hr>\n";$a = addslashes($a);$sql = "... blah = '$a' and ...";echo $sql;?>[/code] Quote Link to comment Share on other sites More sharing options...
paul2463 Posted November 8, 2006 Author Share Posted November 8, 2006 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 methanks anyway Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted November 8, 2006 Share Posted November 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.