将包含特殊字符的值插入MySQL数据库

时间:2014-05-27 07:21:26

标签: php mysql

我目前正在尝试使用TinyMCE设置评论系统,它们都使用普通字符和PHP标记等等。但是当我用这个ed o'neill发表评论时,它只是在我的数据库中插入一个空行。

我的表单输入有htmlspecialcharsmysqli_real_escape_string

如何修复空行插入?

$post_content = $_POST['post_content'];
                        //$post_content = htmlspecialchars($post_content);
                        //$post_content = mysqli_real_escape_string($post_content);

2 个答案:

答案 0 :(得分:3)

看一下准备好的陈述,它会为你做所有的逃避

编辑:Here's the link to the PHP manual, courtesy of Fred -ii-

答案 1 :(得分:2)

您已对某些代码进行了评论,但mysqli_real_escape_string需要2个参数,请参阅更多信息here

string mysqli_real_escape_string ( mysqli $link , string $escapestr );

您的代码应为:

$post_content = mysqli_real_escape_string($connection,$post_content); //$connection should be your database connection string