I'm wondering if it's possible to take a block of text, grab all the commas and convert them into it's corresponding html entity. Something along the lines of what htmlentities($var, ENTQUOTES) does, but for commas.
It could be that I'm overcomplicating the issue. What I'm trying to accomplish is getting a textarea value from a user that may include commas and thus messing up the following code:
$sql = "INSERT INTO blog (title, date, author, article, category)
VALUES (".$title.", ".$date.", ".$author.", ".$article.", ".$category.")";
Having the commas in there messes up the query. I guess I could figure out some other way of doing the insert. (I'm a n00b). Any help is greatly appreciated. Thanks in advance.
*edit: Thanks for the quick replies! The code is protected against injection attacks automatically (codeigniter framework).
The error message is this:
A Database Error Occurred Error Number: 1064
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 'a test post, 07/22/2011, 1, '
This is a test post with all sorts of cool' at line 2
INSERT INTO blog (title, date, author, article, category) VALUES (this is a test post, 07/22/2011, 1, '
This is a test post with all sorts of cool things typed in here as if to be like a real article and everything, but it's not, it's fake. The ultimate blah blah blah repeat:
', news)
I assumed it was because of the commas although I can see now that if they are in the quotes it shouldn't matter. I guess I have a different issue here. Thanks for pointing that out.
*EDIT #2: I used codeigniter's $this->db->escape() on all of the variables and it worked. It wasn't what I thought it was. Sorry for the confusion and thanks for all the advice. The sql injection links have been bookmarked.