嵌入邮箱后未显示帖子列表

时间:2017-06-01 23:30:22

标签: php

我正在尝试使用函数postEmbed()在显示帖子列表之前显示一个帖子框,但在postEmbed()之后没有显示任何内容。
postEmbed():

function postEmbed() { 
if(empty($_SESSION['signed_in'])) {
    exit();
}
else {
echo '<div class="col-sm-4">
        <form method="post" action="">
            <p>'; 
                echo '<textarea id="textarea" class="form-control" name="post_content" /></textarea><p>
        <h6 id="textarea_feedback" class="pull-right"></h6>
                    <input value="Create post" type="submit"  />
                 </form>
        </div>';
                 exit();
        }
$post_id = mt_rand(0,99999999);
$stmt = mysqli_prepare($db, 'INSERT INTO topics(topic_id, topic_cat, topic_by, topic_body)
       VALUES (?, ?, ?, ?)');
mysqli_stmt_bind_param($stmt, 'iiis', $post_id, $_GET["id"], $_SESSION['user_id'], $_POST['post_content']);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
header("Location: http://{$_SERVER['HTTP_HOST']}/communities.php?id={$_POST['topic_cat']}", true, 302);
}

帖子列表(htm.php包含函数postEmbed):

<?php
include 'connect.php';
require_once 'htm.php';
printHeader();
$stmt = mysqli_prepare($db, 'SELECT cat_id, cat_name, cat_description FROM categories WHERE cat_id = ?');
mysqli_stmt_bind_param($stmt, 'i', $_GET['id']);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
    if(!$result || mysqli_num_rows($result) == 0) {
        echo 'This community does not exist.';
        printFooter(); exit();
        }
        $row = mysqli_fetch_assoc($result);
        echo '<div class="page-header"><h1>' . $row['cat_name'] .  '</h1></div>';
        echo '<h3>' . $row['cat_description'] . '</h3><br>';
    echo '<br>';

        $get_posts = mysqli_query($db, 'SELECT * FROM topics WHERE topic_cat = "'.$row['cat_id'].'" ORDER BY topic_date DESC LIMIT 50');

            if(!$get_posts || mysqli_num_rows($get_posts) == 0) {
                echo 'There are no posts in this community yet.';
            printFooter(); exit();
            }

                while($row = mysqli_fetch_assoc($get_posts)) {
                $get_user = mysqli_fetch_assoc(mysqli_query($db, 'SELECT user_name, user_id FROM users WHERE users.user_id = "'.$row['topic_by'].'" LIMIT 1'));
            echo'
        <div class="container">'
        postEmbed();
            echo '
            <div class="panel panel-default">
            <header>
            <div class="panel-heading">' . $get_user['user_name'] . '</span>
            <span class="panel-heading">' . $row['topic_date'] . '</span>
            </header>';
        echo '
            <div class="panel-body">';
                        echo '<div id="post-content">
            <p id="p">' . htmlspecialchars($row['topic_body']) . '</p></div>';
                        echo '<a class="to-permalink-button" href="/' . $row['topic_id'] . '" data-pjax="#body">';
                        echo '</a>
            </div>
            </div>
            </div>
            <br>';

                }

printFooter();
?>

如何使用postEmbed()显示帖子列表:

With

没有postEmbed()时如何显示:

Without

$_SESSION['signed_in']是真的,并且没有SQL错误。

这一直困扰着我一段时间,如果有人能解决这个并给出解释,我会非常感激!

0 个答案:

没有答案