java12 Posted May 13, 2007 Share Posted May 13, 2007 I have a problem comparing surnames from different MySQL tables when the surname field has an apostrophe like O'Neill. The surname from table1 is stored as $name and the surname is selected when it matches the surname field in table2. The lines below work fine until an apostrophe appears. I have tried various things like mysql_real_escape_string, which worked on another issue, but not here. Can anyone suggest where I'm going wrong? <?php // $name is the surname field in table1 $query = mysql_query("SELECT * FROM table2 WHERE surname='$name'"); while ($row = mysql_fetch_array($query)) { echo "$name<br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/51192-apostrophe-problem/ Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 http://uk.php.net/addslashes http://uk.php.net/stripslashes Add the slashes before inserting into the database, and remove them when outputting them. Link to comment https://forums.phpfreaks.com/topic/51192-apostrophe-problem/#findComment-252064 Share on other sites More sharing options...
java12 Posted May 13, 2007 Author Share Posted May 13, 2007 Thanks, but how would you do it when the table1 surname field is already populated? Link to comment https://forums.phpfreaks.com/topic/51192-apostrophe-problem/#findComment-252133 Share on other sites More sharing options...
chigley Posted May 13, 2007 Share Posted May 13, 2007 Not much you can do really, other than edit them/make a script to edit them yourself. Link to comment https://forums.phpfreaks.com/topic/51192-apostrophe-problem/#findComment-252137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.