MySQL查询使用特殊字符

时间:2012-01-12 02:07:50

标签: php mysql

每次使用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";

我该怎么办?

2 个答案:

答案 0 :(得分:3)

mysql_real_escape_string()应该为你逃脱。

答案 1 :(得分:1)

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

相关问题