Jump to content

Need help with the infamous inverted comma thing!


gears

Recommended Posts

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>";
}


?>
Link to comment
Share on other sites

[!--quoteo(post=368355:date=Apr 25 2006, 11:10 AM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 25 2006, 11:10 AM) [snapback]368355[/snapback][/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! :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.