同一变量的多个回声

时间:2015-12-10 05:05:14

标签: php html

所以我有一个变量,叫做$ comments。

但每次我这样做,我都希望它能打破一条线并回应我提交的新线。现在它只是取代现有的。

因此,每次我点击提交时,我都希望它能够发表新评论,而不仅仅是写一篇旧评论。

这是我目前所拥有的,但每次我点击提交它只会覆盖以前的评论。我希望它打破一条线并显示下一条线而不删除之前的

<?php
                session_start();

                if(isset($_POST['add'])){
                $text = $_POST['content'];
                $author = $_POST['author'];
                $comment = $text. ',' .$author;
                $_SESSION['cm'] = $comment;
                echo '<b>';
                }

                ?>

                <!DOCTYPE>
                <html>
                <head>
                    <style>
                        body{
                            text-align: center;
                            margin: 10px 0 0 0;
                        }
                        .listing{
                            text-align: left;
                            border-top: 2px solid #000;
                            padding: 15px;
                        }
                        input{
                            font-size: 16px;
                            padding: 5px;
                            text-align: center;
                        }
                        input[type=submit]{
                            display: block;
                            margin: auto;
                            margin-top: 10px;
                        }
                        #gotolink{
                            position: absolute;
                            top: 15px;
                            right: 15px;
                        }
                        .listing > div{
                            max-width: 100%;
                            word-break: break-all;
                        }




                    </style>
                </head>
                <body>
                    <div id="gotolink"><button onClick='document.getElementById("bottom").scrollIntoView({block: "end", behavior: "smooth"});'>Scroll to bottom</button></div>
                    <p>Try and stay</p>
                        <p>Creating new test</p>
                            <form action="" method="POST">
                            <input type="text" name="content" placeholder="Text">
                            <input type="text" name="author" placeholder="Name">
                            <input type="submit" value="Submit" name="add">
                        </form>
                        <div class="listing">
                            <?php echo '<div>' .$_SESSION['cm']. '</div>';  ?>
                        </div>
                    <div id="bottom"></div>
                </body>
                </html>

1 个答案:

答案 0 :(得分:0)

 $_SESSION['cm'] = $comment;   

替换为:

$_SESSION['cm'] .= $comment."<br>";
相关问题