SPUG: inserting content into mysql database

luis medrano lmzaldivar at gmail.com
Tue Oct 3 10:35:43 PDT 2006


List,

I running this code feeding a database:
my $sth1=$dbh->prepare("INSERT INTO wp_posts(post_author, post_date,
post_date_gmt, post_content,post_title, post_status, comment_status,
ping_status,post_name, post_modified, post_modified_gmt,guid)

VALUES('$post_author','$post_date','$post_date_gmt','@post_content','$post_title','$post_status','$comment_status','$ping_status','$post_name','$post_modified','$post_modified_gmt','$guid')")
 or
die; # "Couldnt prepare statement: " . dbh->errstr;

        my $rv1 = $sth1->execute();


but my problem is if any of the values of @post_content or $post_title
contain apostrophe the script show this error not executing of feeding the
database:

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 's%20secret%20visits%20to%20heiress/article.do">Goldsmith
s secret visits to heir' at line 2 at posting-news.pl

anybody knows how can I fix this without removing the apostrophe?

Thanks,
Luis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20061003/0f3e4fa4/attachment.html 


More information about the spug-list mailing list