Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
他打开了数据库,但什么也没有返回到屏幕。你是否像我一样更改了ajax?您的网络选项卡显示了什么?是的,我更新了ajax。响应是,Warning:date()期望参数2为int,在第32行的/Applications/MAMP/htdocs/activity-tracker.com/blog/post_comment.php中给出的字符串[{“comment”:“_Php_Ajax - Fatal编程技术网

他打开了数据库,但什么也没有返回到屏幕。你是否像我一样更改了ajax?您的网络选项卡显示了什么?是的,我更新了ajax。响应是,Warning:date()期望参数2为int,在第32行的/Applications/MAMP/htdocs/activity-tracker.com/blog/post_comment.php中给出的字符串[{“comment”:“

他打开了数据库,但什么也没有返回到屏幕。你是否像我一样更改了ajax?您的网络选项卡显示了什么?是的,我更新了ajax。响应是,Warning:date()期望参数2为int,在第32行的/Applications/MAMP/htdocs/activity-tracker.com/blog/post_comment.php中给出的字符串[{“comment”:“,php,ajax,Php,Ajax,comment”,“comment_date”:false,“comment_author”:“hullborn75”}数据被插入,但在输出到屏幕时未定义。{comment>:“测试评论”,“发布日期”:“2019年4月10日星期三13:17”,“评论作者”:“hullborn75”}] $stmt = $conn->prepare("SELECT comm.comment, comm.comment_date, m.member_screen_name

comment
”,“comment_date”:false,“comment_author”:“hullborn75”}数据被插入,但在输出到屏幕时未定义。
{comment>:“测试评论
”,“发布日期”:“2019年4月10日星期三13:17”,“评论作者”:“hullborn75”}]
$stmt = $conn->prepare("SELECT comm.comment, comm.comment_date, m.member_screen_name
                        FROM comments comm
                        JOIN members m
                            ON comm.member_id = m.id
                        WHERE comm.entry_id = ?
                        ORDER BY comm.comment_date DESC");
$stmt->bind_param("i", $post_id);
$stmt->execute();
$stmt_result = $stmt->get_result();

if ($stmt_result->num_rows > 0) {
    while($row = $stmt_result->fetch_assoc()) {
        $comment = $row["comment"];
        $comment_date =  date_create($row['comment_date']);
        $comment_date = date_format($comment_date, ' l jS F Y H:i');
        $comment_author = $row["member_screen_name"];

        $comments .= "<div class='comment_div'><div class='small'><p class='text-info'>posted by $comment_author on $comment_date</p>$comment<hr /></div></div>";
    }
}else{
    $comments = "<div class='alert alert-primary' role='alert'>Be the first to comment</div>";
}
$('#submit').click(function (e) {
    e.preventDefault();
    if (!$('#summernote').summernote('isEmpty')) {
        var comment = document.getElementById("summernote").value;
        var member_id = 1;
        var post_id = 1;
        $.ajax ({
            type: 'post',
            url: 'post_comment.php',
            data: {
                comment:comment,
                member_id:member_id,
                post_id:post_id,
            },
            success: function (response) {
                document.getElementById("all_comments").innerHTML=response+document.getElementById("all_comments").innerHTML;
                $("#summernote").summernote("reset");
            },
        });
    }else {
        alert('Please enter a comment');
    }
    return false;
}); 
if(isset($_POST['comment'])){
    $comments = "";
    $comment=$_POST['comment'];
    $member_id =$_POST['member_id'];
    $post_id =$_POST['post_id'];
    if(isset($comment)) {
        $stmt = $conn->prepare("INSERT INTO comments (entry_id, member_id, comment) VALUES (?, ?, ?)");
        $stmt->bind_param("iis", $post_id, $member_id, $comment);   
        $stmt->execute();
        $entry_id = mysqli_insert_id($conn);

        $stmt = $conn->prepare("SELECT comm.comment, comm.comment_date, m.member_screen_name
                                FROM comments comm
                                JOIN members m
                                   ON comm.member_id = m.id
                                WHERE comm.entry_id = ?
                                   AND comm.id = $entry_id
                                ORDER BY comm.comment_date DESC");
        $stmt->bind_param("i", $post_id);
        $stmt->execute();
        $stmt_result = $stmt->get_result();

        if ($stmt_result->num_rows > 0) {
            while($row = $stmt_result->fetch_assoc()) {
                $comment = $comment;
                $comment_date =  date_create($row['comment_date']);
                $comment_date = date_format($comment_date, ' l jS F Y H:i');
                $comment_author = $row["member_screen_name"];

                $comments .= "<div class='comment_div' style='background:red'><div class='small'><p class='text-info'>posted by $comment_author on $comment_date</p>$comment<hr /></div></div>";

                echo $comments ;
             };
            exit;
        }
    }
}else {
    header("location: /blog");
    exit;
}
<script type="text/javascript">
    $('#submit').click(function (e) {
        e.preventDefault();
        if (!$('#summernote').summernote('isEmpty')) {
            var comment = document.getElementById("summernote").value;
            var member_id = 1;
            var post_id = 1;
            $.ajax ({
                type: 'post',
                url: 'post_comment.php',
                data: {
                    comment:comment,
                    member_id:member_id,
                    post_id:post_id,
                },
                dataType : "json",
                encode   : true,
                success: function (data) {
    $.each(data, function(index, element){ 
$('#all_comments').append("<div class='comment_div' style='background:red'><div class='small'><p class='text-info'>posted by " +element.comment_author + "on " + element.post_date+"</p>"+element.comment+"<hr /></div></div>"); 
}); 

$("#summernote").summernote("reset"); 
$('.alert').empty();
                },
            });
        }else {
            alert('Please enter a comment');
        }
        return false;
    });
</script>
 <?php
if (isset($_POST['comment'])) {
    $comment       = $_POST['comment'];
    $member_id     = $_POST['member_id'];
    $post_id       = $_POST['post_id'];
    $commentsArray = array();
    $stmt          = $conn->prepare("INSERT INTO comments (entry_id, member_id, comment) VALUES (?, ?, ?)");
    $stmt->bind_param("iis", $post_id, $member_id, $comment);
    $stmt->execute();

    $entry_id = mysqli_insert_id($conn);

    $stmt = $conn->prepare("SELECT comm.comment, comm.comment_date, m.member_screen_name
                                FROM comments comm
                                JOIN members m
                                ON comm.member_id = m.id
                                WHERE comm.entry_id = ?
                                AND comm.id = ?
                                ORDER BY comm.comment_date DESC");
    $sql->bind_param("ii", $post_id, $entry_id);
    $sql->execute();
    $sql_result = $sql->get_result();

    if ($stmt_result->num_rows > 0) {
        while ($row = $stmt_result->fetch_assoc()) {
            $comment_date =  date_create($row['comment_date']);
            $commentsArray[] = array(
                'comment' => $comment,
                 'post_date' = date_format($comment_date, ' l jS F Y H:i');
                'comment_author' => $row['member_screen_name']
            );
        }

    }


    echo json_encode($commentsArray);
}
$('.alert-primary').hide()