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

I have one guestbook application where an user can enter his name, email and message and then it’s stored on a database which I open it afterwards through a php file to view the comments.

My question is: How can I add those comments (when the user clicks submit buttoN) directly to the html page under the comment box in descending order by post hour/date? ( i don’t need the date/hour to be displayed, I just want the comments to be placed consecutively)

I use guestbook.php to take the data from db and display it when a user clicks on it(it’s a button on my index.html page named Guestbook). Here is the code for Guestbook.php:

$host="localhost"; //Add your SQL Server host here
$user="db1"; //SQL Username
$pass="test123"; //SQL Password
$dbname="db1"; //SQL Database Name
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 } 

And I’ll show u the part of my index.html code(the body) which contains the name, email, message box, security check box and the footer:

<ul id="mainMenu">
    <li><a href="index.html">Home</a></li>
    <li><a href="guestbook.php" id="active">Guestbook</a></li>
<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" />
<div id="footer">
<p>Thank you for the visit! </p>

So, i’m thinking that somehow it’s possible to replace the footer with a section which will contain the comments underneath…but idk how to take those comments from db and place them there using html code

Thanks in advance!


If I get you right, what you want to do is:

  1. Rename your index.html to index.php
  2. Add <?php include ("guestbook.php"); ?> to the file where you want the entries to appear.