我有一个留言簿应用程序,用户可以输入其名称、电子邮件和消息,然后将其存储在数据库中,然后通过php文件打开数据库查看评论。
我的问题是:如何将这些注释(当用户单击submit buttoN时)直接添加到注释框下的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>因此,我认为可以用一个包含注释underneath...but idk的部分替换页脚--如何从db获取这些注释,并使用html代码将它们放在那里
提前感谢!
发布于 2017-02-07 21:14:53
如果我说的对,你想做的是:
index.html重命名为index.php<?php include ("guestbook.php"); ?>添加到要显示条目的文件中。发布于 2017-02-07 21:10:51
使用.prepend()函数:
var information = ""; // The information from the form.
$("#footer").prepend(information);https://stackoverflow.com/questions/42100028
复制相似问题