如何使用php将带有特殊字符的字符串从表单存储到mysql数据库?

时间:2014-01-20 14:00:04

标签: php mysql xampp

我正在使用xampp

我使用$_POST[]从表单文件的文本框中获取文本,以将其存储在表格中。

如果在表单中输入的文本包含任何这些字符(,.?' " \ ; :> <!...),则会返回如下错误消息,

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's missile_carrier?' at line 3

输入的文字为"China hails: first; test of-hypersonic nuclear's missile_carrier?"

如何让它接受包含这些字符的文字((,.?' " \ ; :> <!...) ...

请帮助

1 个答案:

答案 0 :(得分:0)

建议请使用mysqli,然后使用mysqli_real_escape_string http://uk3.php.net/manual/en/mysqli.real-escape-string.php