I'm inserting some HTML into a MySQL database table. But when I get it back, many characters are mangled. Two specific cases I noted are:
- the single quotes are getting converted to �,
- code that earlier read
class='content-section developer-support'
has got converted todeveloper-support\="" class="\'content-section"
I understand that its an escaping problem. I use mysql_real_escape_string on the field before I push it into the db.
What is the right way to avoid this problem?
source:
$query = sprintf("insert into events (title, content) values('%s', '%s')",
mysql_real_escape_string($this->title, $conn),
mysql_real_escape_string($this->content, $conn)
);
the text I'm talking about is inserted into the field content
.
And yes, I do have magic_quotes enabled. I'll fix that.. thanks