Home: Perl Programming Help: DBI:
HTML in mySQL (what to do with " and ')



skirrow
stranger

Feb 8, 2003, 6:02 AM


Views: 14003
HTML in mySQL (what to do with " and ')

Hi,
I need to include some HTML in my mySQL database. The problem is, what type of field should I make it and how to insert it?

When inserting to the db, the HTML is submitted via dbi like so:

$query = qq(insert into table (html) Values ("$html"));

The problem here is the value is held with either " or '. Both of these symbols are regularly used in HTML so the query is rejected.

Does anyone has any suggestions for how to resolve this problem?

All help is very much appreciated!!
- Neil
--
http://www.locked-area.com/
http://www.opencrypt.com/


Paul
Enthusiast

Feb 8, 2003, 6:49 AM


Views: 14000
Re: [skirrow] HTML in mySQL (what to do with " and ')

As mentioned in the DBI docs (which I'd advise you to read) use $dbh->quote($html)


skirrow
stranger

Feb 8, 2003, 6:59 AM


Views: 13998
Re: [Paul] HTML in mySQL (what to do with " and ')

Thank you, will have a look for quote in docs.
- Neil
--
http://www.locked-area.com/
http://www.opencrypt.com/


Paul
Enthusiast

Feb 8, 2003, 7:40 AM


Views: 13996
Re: [skirrow] HTML in mySQL (what to do with " and ')

Last in this sub section:

http://www.perldoc.com/cpan/DBI.html#Database-Handle-Methods


(This post was edited by Paul on Feb 8, 2003, 7:40 AM)


erichmusickwc
Novice

Mar 3, 2003, 9:42 PM


Views: 13983
Re: [Paul] HTML in mySQL (what to do with " and ')

Another method, the one I use:


Code
my $sth = $dbh->prepare("INSERT INTO sometable (yeah,whatever) VALUES(?,?) || die(DBI->errstr);  

$sth->execute($valueForYeahField,$valueForWhateverField) || die(DBI->errstr);

$sth->finish();



Preparing the statement also allows you to execute it multiple times. So, inbetween the prepare and finish, for example, you could execute the query 10 different times, each time with different values, while looping through a block.