MySQL查询使用特殊字符


MySQL query using special characters

每次使用SQL查询插入数据时都会出现错误。我怀疑是因为$post值中有撇号。

SQL查询是:

$sql="INSERT INTO posts (id_str, post, time, rt) VALUES ('$id_str','$post', '$time', '$rt')";

但是我的$post值是

$post = "My test posts are not as 'inconsistent' as before";

我该怎么办?

mysql_real_aescape_string()应该为您执行转义。

最基本的解决方案是mysql_real_escape_string()