获取其他表的id并插入另一个表

时间:2017-02-18 22:43:36

标签: php mysqli comments

我在为我的网站制作评论部分时遇到了问题。每当我发表评论时,只有一条评论保存在我的表格中,我不知道是什么错误因为我已经在while中插入代码来循环问题的id并插入每个评论ID。这是html和php代码。

<?PHP

session_start();
include "function.php";

$con    = db();
?>

<div class="row">
    <div class="col-md-8">
        <div class="panel panel-default">
            <div class="panel-heading"><div class="panel panel-green"><svg style="margin-left:20px" class="glyph stroked app window with content"><use xlink:href="#stroked-app-window-with-content"></use></svg><b>Question and  Answer</b>
        </div>
    </div>
    <div class="panel-body">
        <form class="form-horizontal" action="" method="post">
        <fieldset>
            <table data-toggle="table" data-url="tables"  data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar1" data-pagination="true" data-sort-name="name" data-sort-order="desc">
                <br>
<?PHP
    $sql = "SELECT * FROM tbl_alum_question ORDER BY ques_id desc";
    $result = mysqli_query($con, $sql);
    if(mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_array($result)) {

            echo '<form action="" method="post" >';
            echo '<p style= "text-align: right;">'; echo ''.$row["created"].''; 
            echo '</p>';
            echo '<p>&nbsp;Asked by:</p>';
            echo '<p >'; 
            echo ''.$row["questions"].''; 
            echo '</p>';
            echo '<input type="hidden" name="comment_id" value="';
            echo ''.$row['ques_id'].'' ;
            echo '">';

            //echo '<form action="" method="post" style="display: block;"';
            echo '<input name="commentid" id="commentid"type="hidden" value="'.$row['ques_id'].'">';
            echo '<input type="text" name="reps" value=""style="display: block;"><br>
            <input type="submit" name="reply" value="Comment"/><br>';
            //echo '</form>';
            //echo '<input type="text" name="reps" /><br>
            echo '</form>';

            if(isset($_POST['reply'])) {
                $id = $_POST['commentid'];
                $reps = $_POST['reps'];
                $datetime=date("Y/m/d h:i:sa");

                $sqq = 'INSERT INTO tbl_alum_answer 
                                    (ques_id, answer, created, username) 
                        VALUES ("'.$id.'","'.$reps.'","'.$datetime.'","red" )';
                $ress = mysqli_query($con, $sqq);
            }
        }
        echo '</div>';
    }
?>
<?php
?>
        </table>
        </fieldset>
        </form>
    </div>

    </div>
    </div><!--/.col-->

0 个答案:

没有答案