CASE CLOSED: Thanks to people for pointing out how PHP would have solved this. A little bit of web searching revealed that there’s a simple solution in Perl as well — and it turns out that this was partially implemented. We allowed apostrophes in the story headlines, but not in the source. It was a simple case of substitution, adding an escape character, and when we added this to the Perl code it worked.
We discovered this problem on LabourStart’s Italian page. If we try to add a news story and in the source field key in, for example, l’Unita, the attempt is rejected. We’re using a Perl script to do this, and the relevant lines are follow. The field source field is called $source and you can see that the new input field is enclosed in apostrophes, which is almost certainly what’s causing the problem. Can you help us?
Here’s the code:
use DBI;
$db = DBI->connect(‘dbi:mysql:***:***’,'***’,'***’);
if ($modify eq 1) { # delete old record first
$db->do(“DELETE FROM news WHERE url=’$url’”) || die (‘Could not delete record.’);
}
$db->do(“INSERT INTO news (url, header, country, country2, date, priority, userid, source, formoreinfo, language, regreqd, keywords, image, actnowcampaigncode, state, dateposted) VALUES (‘$url’, ‘$header’, ‘$country1′, ‘$country2′, $date, $priority, ‘$userid’, ‘$source’, ‘$formoreinfo’, ‘$language’, ‘$regreqd’, ‘$keywords’, ‘$image’, ‘$actnowcampaigncode’, ‘$state’, $date)”) || die (print qq|<span style=”color: red; font-weight: bold; background-color: yellow; padding: 5px; border: 1px red dotted”>Could not add record.</span>|);$db->disconnect();
3 September 2008 at 1:56 pm
Sounds like you need to “escape” the apostrophes:
http://www.faqts.com/knowledge_base/view.phtml/aid/630
3 September 2008 at 2:17 pm
Yep. If it was a PHP page, the command to use would be addslashes(). Unfortunately, I don’t know Perl.