遇到mysql_real_escape_string的问题,之前没问题

时间:2013-09-19 18:56:28

标签: php

我将以我的问题为例。这个代码在6小时后完美,但现在有一些问题,我不知道它是什么?

这是我的小PHP。我能够发现问题是 mysql_real_escape_string ,但我不知道如何快速修复这个该死的。

<?php
// database connection
require_once 'includes/inc/config.php';
$date = new DateTime();
$newtime = $date->format('U');
// we are taking post_text = <img id="profile_pic" width="200px" height="600px" src="image/user/1.jpg">
if (isset($_POST['submit-post'])) {
    $content = mysql_real_escape_string($_POST['post_text']);
    if ($got != "" && $send != "" && strlen(trim(preg_replace('/\xc2\xa0/',' ',$content))) != 0) {
        $postnow = mysql_query("INSERT INTO `comment`(`send`,`got`,`content`,`time`) VALUES ('$send','$got','$content','$newtime')");
    }
}
?>

显示

<?php

require_once 'library/all/HTMLPurifier.auto.php';

// reading content which was saved when user posted comment
// getting it from database ex: <img id="profile_pic" width="200px" height="600px" src="image/user/1.jpg">

$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$content = $purifier->purify($content); 

// and then echo

echo $content;

?>

这是我在每个页面上显示的帖子。

这是我的输出我得到的内容

这是破碎的图像,在没有破坏之前,知道发生了什么?

<img id=\"profile_pic\" width=\"200px\" height=\"600px\" src=\"image/user/1.jpg\">

PS:这仍然适用于localhost。如果我的服务器提供商升级或类似的话,我有点困惑。我不知道。谢谢大家。

1 个答案:

答案 0 :(得分:6)

上面列出的行为是正确的行为。有问题的功能

mysql_real_escape_string

旨在以特定方式清理输入到MySQL数据库,这样就不会在INSERT,UPDATE等上出现错误。