簡體   English   中英

如何在 html+php+mysql 制作的留言簿的評論框下方放置評論?

[英]How to Place comments right under the comment box in a guestbook made in html+php+mysql?

我有一個留言簿應用程序,用戶可以在其中輸入他的姓名、電子郵件和消息,然后將其存儲在數據庫中,然后我通過 php 文件打開它以查看評論。

我的問題是:如何按發布時間/日期降序將這些評論(當用戶單擊提交按鈕時)直接添加到評論框下的 html 頁面? (我不需要顯示日期/小時,我只想連續放置評論)

我使用guestbook.php 從db 獲取數據並在用戶單擊它時顯示它(它是我的index.html 頁面上名為Guestbook 的按鈕)。 以下是 Guestbook.php 的代碼:

<?php
$host="localhost"; //Add your SQL Server host here
$user="db1"; //SQL Username
$pass="test123"; //SQL Password
$dbname="db1"; //SQL Database Name
$con=mysqli_connect($host,$user,$pass,$dbname);
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT name,message FROM db1");
while($row = mysqli_fetch_array($result))
{ ?>
<h3><?php echo $row['name']; ?></h3>
<p><?php echo $row['message']; ?></p>
<?php } 
    mysqli_close($con);
?>

我將向您展示我的 index.html 代碼(正文)的一部分,其中包含姓名、電子郵件、消息框、安全復選框和頁腳:

<ul id="mainMenu">
    <li><a href="index.html">Home</a></li>
    <li><a href="guestbook.php" id="active">Guestbook</a></li>
</ul>
<hr/>
</div>
<div id="content">

<h2>Sign to the Guest Book </h2>
    <form name="guest" method="post" action="addcomment.php" onsubmit="return Validate();">
        <span>Name:</span>    <input type="text" name="name"/><br />
        <span>Email:</span> <input type="text" name="email"/><br />
        <p>Message:</p> <textarea name="message" rows="10" cols="50"> </textarea> <br />
        <p>5+5 = ? (in letters):</p> <input type="text" name="res"> </textarea> <br />
        <input type="submit" value="Sign this in the Book" />
  </form>
</div>
</div>
<div id="footer">
<hr/>
<p>Thank you for the visit! </p>
</div>
</body>
</html>

所以,我想以某種方式可以用包含下面評論的部分替換頁腳......但是idk如何從數據庫中獲取這些評論並使用html代碼將它們放在那里

提前致謝!

使用.prepend()函數:

var information = ""; // The information from the form.
$("#footer").prepend(information);

如果我猜對了,你想做的是:

  1. 將您的index.html重命名為index.php
  2. 添加<?php include ("guestbook.php"); ?> <?php include ("guestbook.php"); ?>到您希望條目出現的文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM