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. Link to comment https://forums.phpfreaks.com/topic/26604-how-to-comment-out-an-apostrophy-in-an-sql-statement/ 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] Link to comment https://forums.phpfreaks.com/topic/26604-how-to-comment-out-an-apostrophy-in-an-sql-statement/#findComment-121762 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 Link to comment https://forums.phpfreaks.com/topic/26604-how-to-comment-out-an-apostrophy-in-an-sql-statement/#findComment-121768 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. Link to comment https://forums.phpfreaks.com/topic/26604-how-to-comment-out-an-apostrophy-in-an-sql-statement/#findComment-121770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.