从帖子插入文字“

时间:2015-10-21 01:15:54

标签: php mysql

我正在尝试找出如何将文本插入包含'和'的mysql;我尝试了mysqli_real_escape_string它只是将它们全部停在一起,所以这是不可能的。我当前的代码插入是< / p>

    public function SubmitReply() {
        $query = <<<SQL
        INSERT INTO {$this->tprefix}posts(guid,poster,content,postdate)
        VALUES(:guid,:poster,:content,:postdate)
SQL;
        $resource = $this->db->db->prepare( $query );
            $resource->execute( array (
            ':guid' => $_POST['guid'],
            ':poster'   => $_POST['poster'],
            ':content'  => htmlspecialchars($_POST['editor']),
            ':postdate' => $_POST['postdate'],
            ));
            print_r($_POST);
            print_r($_GET);
            return $resource->rowCount();
    }

然后它被读作

    public function LoadPosts() {
        echo "Under Development";
        $cnvtpc = str_replace("_", " ", $_GET['topic']);
        $query = <<<SQL
        SELECT poster,content,postdate
        FROM {$this->tprefix}posts 
        WHERE guid = :converted
SQL;
        $resource = $this->db->db->prepare( $query );
        $resource->execute( array (
        ':converted'    => $cnvtpc,
        ));
        foreach($resource as $row ) {
            echo '<tr><td class = "profile">'.self::TranslateToText($row['poster']).'</td><td class="content">'.htmlspecialchars_decode($row['content']).'</td><td class="details">Posted On '.$row['postdate'].'</td></tr>';
        }
    }

现在,如果有人发布内容很好,除非他们想发帖, I'm using this code right now and it works great然后插入I,然后'打破剩余的插入。

好。我能够获得更多可能有助于显示问题的数据。 我的帖子输出来自插入带撇号的记录:

Array ( [process] => DEF_FORUM_SUBMIT_REPLY [guid] => Forum Rules [poster] => 1 [postdate] => 2015-10-21 01:36:07 [editor1] => [editor] =>
Let [#39;s_see_what_the_apostrophe_returns_in_post_

] => )

我们现在看到另一个POST变量已经以某种方式动态创建。 (让我感到意外的是,我有一些我想在以后工作的东西,这取决于动态的帖子) 所以问题已缩小到编辑帖子实际上只是Let,而现在有一个$_POST['#39;s_see_what_the_apostrophe_returns_in_post_ (Some whitespace here)']的值为零,所以我的ajax数据是

data: $("#reply").serialize() + "&editor=" + textarea,

只要输入数据就已修复,但现在我的ajax无法正常工作并重定向。 目前的代码是

             <script>
$(function() {
  $('#reply').submit(function(event) {
    var $("#editor1").val() = CKEDITOR.instances.editor1.getData();
    $.ajax({
      type: $("#reply").attr("method"),
      url: $("#reply").attr('action'),
      data: $("#reply").serialize(),
        success: function(data){
            $(".processing").html(data);
        }
    });
    event.preventDefault(); // Prevent the form from submitting via the browser.
    });
});
</script>

这是表格本身

<form id="reply" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="process" id="process" value="DEF_FORUM_SUBMIT_REPLY">
<input type="hidden" name="guid" id="guid" value="<?php DEF_TOPIC_NAME($_GET['topic']); ?>">
<input type="hidden" name="poster" id="poster" value="<?php echo $_SESSION['key']['userid']; ?>">
<input type="hidden" name="postdate" id="postdate" value="<?php echo gmdate('Y-m-d H:i:s'); ?>">


            <textarea name="editor1" id="editor1" rows="10" cols="80"></textarea>
            <p style="text-align:center; margin-top:10px;">
            <input type="submit" class="btn btn-success" value="Post Reply" id="submit_reply"></p>
            </form>
            <div class="processing"></div>

因此使用CKeditor手动定义Javascript中的值,因为如果你没有得到它,那么它只是在post数据中没有传递任何内容。

0 个答案:

没有答案