PHP file_id用于3个不同的网页

时间:2016-05-09 17:26:11

标签: php mysql

我不知道file_id应该如何正常工作。我希望获得3个子页面的评论系统,其中嵌套了不同的注释,这意味着我需要为每个网站提供唯一的$ file_id。这是代码:

<?php
function get_comments($file_id) {
    include 'database.php';
    $result = mysqli_query($connect, "SELECT * FROM `comments` WHERE `file_id`='$file_id' AND `is_child`=FALSE ORDER BY `date` DESC");
    $row_cnt = mysqli_num_rows($result);
    echo '<h1>Comments ('.$row_cnt.')</h1>';
    echo '<div class="comment">';
        new_comment();
    echo '</div>';
    foreach($result as $item) {
        $date = new dateTime($item['date']);
        $date = date_format($date, 'M j, Y | H:i:s');
        $auth = $item['author'];
        $par_code = $item['com_code'];
        $chi_result = mysqli_query($connect, "SELECT * FROM `comments` WHERE `par_code`='$par_code' AND `is_child`=TRUE");
        $chi_cnt = mysqli_num_rows($chi_result);
        echo '<div class="comment" name="'.$item['com_code'].'">'
                .'<span class="author">'.$auth.'</span><br />'
                .$item['comment'].'<br />'
                .'<span class="date">Posted: '.$date.'</span><br />'
            .'</div>';
    }
    mysqli_close($connect);
}
function add_comment($reply, $code) {
    echo '<form action="reply.php" method="post" enctpye="" name="new_comment">'
            .'<input type="hidden" name="par_code" value="'.$code.'" />'
            .'<textarea class="text_cmt" name="text_cmt" placeholder="Reply to '.$reply.'"></textarea><br />'
            .'<input type="submit" value="Reply" />'
        .'</form>';
}
function new_comment() {
echo '<form action="new.php" method="post" enctpye="" name="new_comment">'
        .'<textarea class="text_cmt" name="text_cmt" placeholder="Post a new comment"></textarea><br />'
        .'<input type="text" name="text_author" required/><br/>'
        .'<input type="submit" value="Post" />'
    .'</form>';

以下是运行new_comment

的代码
<?php
require_once 'database.php';
require_once 'functions.php';

$reply = $_REQUEST['text_cmt'];
$date = date('Y-m-d H:i:s');
$reply_author = $_REQUEST['text_author'];

$rand = generateRandomString();
    #checkString($rand);

mysqli_query($connect, "INSERT INTO `comments` (`file_id`, `comment`, `com_code`, `is_child`, `par_code`, `author`, `date`) VALUES ('$file_id', '$reply', '$rand', '', '', '$reply_author', '$date')");

header("Location: http://orfi.uwm.edu.pl/~s119434/przepisy.php");
?>

0 个答案:

没有答案