Forum Moderators: coopster & phranque

Message Too Old, No Replies

using perl to insert a while html page into mysql with dbi

         

jeremy goodrich

5:09 pm on May 13, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



trying again and again to insert this to a database however, I can't figure out how to properly escape the html but that doesn't seem to work. Any ideas?

here's some sample code:

[perl]
use dbi;

# connect to database
&openDatabase;

$sqlquery = $dbh->prepare (qq{INSERT INTO table (var1,var2,var3,var4,var5) VALUES ('$var1','$var2','$var3','$var4','$var5') });

$sqlquery->execute();
$sqlquery->finish();
&closeDatabase;

[/perl]

I've tried also using
[perl]
$var2 = $dbh-> quote($var2); [/perl]

but that doesn't work either. I keep getting a 'syntax error ' on line X where X is the line where the $sqlquery variable in the script, and then a snippet of the html I was trying to insert.

Is the problem that I need to url encode the html? Or...? Thanks.

Josk

8:23 am on May 14, 2002 (gmt 0)

10+ Year Member



Perhaps because you using execute..? My equivlilent would be:

$dbh = get_handler();

$dbh->do($sql) ¦¦ die "error in $sql\n";

disconnect_db($dbh)

I've never used anything more complex, and it always seems to work

Lisa

8:27 am on May 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are inserting a blob? Into which database? Have you excaped the text?

sugarkane

8:34 am on May 14, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you use $dbh->quote(), and then put the variables into the VALUES() section of the SQL without quotes - eg VALUES($var1, $var2) - then it should work okay?

jeremy goodrich

3:46 pm on May 15, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



he he, forgot to reply to this post I made.

Actually, the problem I was having (it was a text field) was solved by escaping all the double and single quotes.

:)

eg,
[perl]
$html =~ s/\"/\\"/ig;
$html =~ s/\'/\\'/ig;
[/perl]

thanks for replying though.