ianco Posted February 18, 2013 Share Posted February 18, 2013 Hi all. I've been looking at this for several hours not with no progress. I feel it should be simple but I'm getting nowhere. Here's the problem. I want to provide a list of links where from a table called pages. When $title = "Dave's comment"; for example I get nothing back. If there is no apostrophe in the field it works fine. It's as though I can't find the field. $query = mysql_query("SELECT * FROM pages WHERE title = '$title' ORDER BY pageid DESC LIMIT 20"); while($row = mysql_fetch_assoc($query)) { $title = $row['title']; echo $title; } any ways around this? Thanks Ian Quote Link to comment https://forums.phpfreaks.com/topic/274630-cant-search-table-when-apostrophes-present/ Share on other sites More sharing options...
Jessica Posted February 18, 2013 Share Posted February 18, 2013 You need to read up on data sanitizing. In addition to just plain not working, your script is open to SQL injection. If you were checking for MySQL errors as well you'd get a useful error explaining why it doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/274630-cant-search-table-when-apostrophes-present/#findComment-1413134 Share on other sites More sharing options...
ianco Posted February 18, 2013 Author Share Posted February 18, 2013 I get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's add' ORDER BY pageid DESC LIMIT 20' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/274630-cant-search-table-when-apostrophes-present/#findComment-1413136 Share on other sites More sharing options...
Jessica Posted February 18, 2013 Share Posted February 18, 2013 Yep. Now go do the research I told you to, and it will make sense. Quote Link to comment https://forums.phpfreaks.com/topic/274630-cant-search-table-when-apostrophes-present/#findComment-1413138 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.