You need to escape your strings, looks like mysql_real_escape_string
will do the job in PHP.
Albin Sunnanbo
2010-10-17 06:30:30
You need to escape your strings, looks like mysql_real_escape_string
will do the job in PHP.
Are you escaping the HTML before attempting to insert it into the database? Assuming your HTML is stored in the variable $html
$html = mysql_real_escape_string($html);
$sql = "INSERT INTO html_docs (html) VALUES('$html')";
mysql_query($sql);
The normal advice is don't concatenate parameters and code to build the SQL; use static SQL and pass data as parameters. All decent SQL APIs have parameter-binding mechanisms.
However, AFAICT, there is no such mechanism in PHP database APIs. Instead, it seems that you should use mysql_real_escape_string
to escape strings before injecting them into your SQL statements. Please, someone tell me that I'm wrong and that the PHP authors aren't that stupid.