Jump to content

can't search table when apostrophes present


ianco

Recommended Posts

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

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.

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.