CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



skirrow
stranger

Feb 8, 2003, 6:02 AM

Post #1 of 5 (6254 views)
HTML in mySQL (what to do with " and ') Can't Post

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

Post #2 of 5 (6251 views)
Re: [skirrow] HTML in mySQL (what to do with " and ') [In reply to] Can't Post

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

Post #3 of 5 (6249 views)
Re: [Paul] HTML in mySQL (what to do with " and ') [In reply to] Can't Post

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

Post #4 of 5 (6247 views)
Re: [skirrow] HTML in mySQL (what to do with " and ') [In reply to] Can't Post

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

Post #5 of 5 (6234 views)
Re: [Paul] HTML in mySQL (what to do with " and ') [In reply to] Can't Post

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.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives