2012-01-12 102 views
0

每當我使用SQL查詢插入數據時,都會出現錯誤。我懷疑這是因爲$post值中的撇號。使用特殊字符的MySQL查詢

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"; 

我應該怎麼辦?

回答

3

mysql_real_escape_string()應該爲你逃跑。

+1

沒錯。在接受來自用戶的輸入之前,總是試圖查看安全問題。 – 2012-01-12 02:11:51

1

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