So if you’ve ever tried to make a comment on one of our MANY comics (101 real comics as of right now!) you most likely will have seen an error page showing an ever so confusing MySQL Error if you used an apostrophe and/or single quote in your comment.
The way PHP & MySQL works to do an insert you have to basically nest double and single quotes around the info. This is a problem for a person just typing away because they don’t know that. I guess I’ve been proactive lately and figured out how to fix it.

str_replace("'", "&#39", "YOUR COMMENT");

basically it replaces any single quote with it’s ASCII equivilent.

“But Josh, that looks ridiculously simple!”

Yea, it’s simple … now! Never needed to do that before and was hoping I could mess with the syntax enough to get it to not error out with either a double or single quote. But no …. lol

So uh … COMMENT AWAY!!!

-josh

Technorati Tags: ,