Apostrophe Problem

Posted on 2006-05-06
Last Modified: 2013-12-25
I am coming up with a problem when I submit text with an apostrophe in the text from a textbox to mysql using perl.

Error mesage I get is:
DBD::mysql::st execute failed: 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 't

When for example i use the word "doesn't" in the text.

I know I should be using escaped characters but I can't seem to get the apostrophe part working.  

For newline I use the following command:
$text =~ s/\n/<br>/g;

Can you please help.
Question by:falthorn
    LVL 19

    Accepted Solution

    MySQL requires single quotes to be deleimited by another quote such as:  d o e s ' ' t.

    If you use placeholder, DBI will handle all the quoting for you
    $sth = $dbh->prepare("INSERT INTO table(foo,bar) VALUES (?,?");
    $sth->execute( $foo, $bar);  # $bar  can contain single quotes

    Author Comment

    Thank you teraplane,  it worked a treat.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
    This article will show, step by step, how to integrate R code into a R Sweave document
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now