ezekiel has asked for the wisdom of the Perl Monks concerning the following question:
I have a CGI script attempting to store information obtained by a form in a MySQL database. The statement looks something like this:
# $comment contains the user form input my $sql = "insert into my_table " . "(COMMENT) " . "values ('$comment')"; my $sth = $dbh->prepare($sql); my $rc = $sth->execute();
This works fine when $comment is a bunch of text (e.g. "my comment"), but crashes when $comment contains text including a single quote (e.g. "Ezekiel's comment"). I can parse $comment so it contains "Ezekiel''s comment" i.e. escape the single quote with another single quote, but I am wondering if there is a better way to do this as:
Can someone point me in the direction of tools to check incoming CGI parameters and prepare the contents for insertion into a database?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Escaping single quotes and DBI
by maverick (Curate) on Sep 06, 2001 at 07:44 UTC | |
|
Re: Escaping single quotes and DBI
by lachoy (Parson) on Sep 06, 2001 at 07:42 UTC | |
|
Re: Escaping single quotes and DBI
by pmas (Hermit) on Sep 06, 2001 at 09:42 UTC | |
|
Re: Escaping single quotes and DBI
by ezekiel (Friar) on Sep 06, 2001 at 11:37 UTC | |
|
Re: Escaping single quotes and DBI
by flocto (Pilgrim) on Sep 06, 2001 at 14:30 UTC |