Jump to content


Photo

Need help with the infamous inverted comma thing!


  • Please log in to reply
2 replies to this topic

#1 gears

gears
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 April 2006 - 09:33 AM

Guys,

I've written a really quick and rather crappy script which compares two tables. It does this because my content management system on www.coolsmartphone.com puts news stories in one table, but the commenting system uses another table. Anyhoo, I wrote a script that compares the two fields in two tables and fires out the result as a URL, so that users can click the appropriate link. All is well until I enter a news item with a subject like "It's here" or "That's the way to do it" etc etc - you get the picture. Although the "LIKE" command in MySQL is doing it's job, the "mysql_result($leigh2, 0);" isn't working when a -- ' -- is in the subject line. How do I get it to select it and IGNORE that ? The -- ' -- symbol can't be changed in the database, so I need some way of saying, "grab this field as a whole".

Here's the script. Yes, crap.. yes, there's probably a neater way of doing it.. but I was drunk at the time I wrote it.. :)

<?php
$titlenew = htmlspecialchars("$title[$i]");
$leigh="SELECT * from phpbb_topics where topic_title LIKE '$titlenew'";
$leigh2=mysql_query($leigh) or die("Could not select it");
$leigh3=mysql_fetch_array($leigh2);
$thelinky=mysql_result($leigh2, 0);
$thecounter=mysql_result($leigh2, 0, 6);

if(!$leigh3)
{
echo "No link yet";
}

else
{
print "<a href=\"http://www.coolsmartphone.com/forum/posting.php?mode=reply&t=$thelinky\"><B>Add</a></b> or <a href=\"http://www.coolsmartphone.com/forum/viewtopic.php?t=$thelinky\"><B>view comments ($thecounter)</a></b>";
}


?>

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 25 April 2006 - 10:10 AM

You need to look into strip_slashes and add_slashes.

The database my have the titles stored as:

That\'s the way to do it

and you query is looking for:

That's the way to do it

or vice versa.
follow me on twitter @PHPsycho

#3 gears

gears
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 25 April 2006 - 10:36 AM

[!--quoteo(post=368355:date=Apr 25 2006, 11:10 AM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 25 2006, 11:10 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You need to look into strip_slashes and add_slashes.

The database my have the titles stored as:

That\'s the way to do it

and you query is looking for:

That's the way to do it

or vice versa.
[/quote]


Excellent ! What a muppet I am for not finding that :) Changed it to ...

<?php
$titlenew = addslashes(htmlspecialchars("$title[$i]"));
......

and everything works fine! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users