How To Add Comment Field On Your Website Using PHP-MySQL
What Will I Learn?
- You will learn how to add a comment field to your website
- You will learn how to create a table for a website
- You will learn how to make connections between PHP and MySQL
Requirements
- you should be able to basics of PHP programming
- you should be able to the basics of MySQL
- you should be able to create a MySQL database
Difficulty
- Basic
Tutorial Contents
the comment field for a website page is absolutely necessary, the comment field will accommodate suggestions, and criticism from the visitors, the famous website also uses the comment field so that visitors can write their complaints in the column, for those of us who just create the under the advice website is very necessary because there are still many shortcomings in our web pages.
this time I will give tutorial how to create comment field for a website </ b>
- the first step you must do is create a database that serves to save comments from the visitors.
- then run APACHE and MySQL on your XAMPP app.

function so that we can create a database
- then open your browser type ``` http: // localhost / xampp / `` `in the search field of your browser.

choose phpMyAdmin
- create a database like the image below through the MySQL GUI

- the database we have successfully created, then we will design the form of the comment column
- type the code below to design the form from the comment form.
<?php
mysql_connect ("localhost","root","");
mysql_select_db ("db_komentar");
$tanggal = date ("Ymd");
$time = date ("H:i:s");
// menambah data ke dalam tabel
$kueri = mysql_query ("INSERT INTO tb_komentar(nama, website, pesan, tanggal, time) values ('$_POST[nama]', '$_POST[website]', '$_POST[pesan]', '$tanggal','$time')");
$query = mysql_query ("SELECT * FROM tb_komentar ORDER BY time || tanggal DESC");
while ($d = mysql_fetch_array ($query))
{
$psn = $d['pesan'];
echo "<table>";
echo "<tr><td><b>$d[nama] : $psn</b></td></tr>";
echo "<tr><td><i>Website : $d[website]</i></td></tr>";
echo "<tr><td align=right>$d[time]: $d[tanggal]</td></tr></table><hr>";
}
?>
</body>
</html>
<html>
<head>
<title>Kolom Komentar</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="simpann.php">
<table width="200" border="1">
<tr>
<td colspan="2"><strong>Tingggalkan Komentar Anda : </strong></td>
</tr>
<tr>
<td width="96">Nama</td>
<td width="88"><label for="textfield"></label>
<input type="text" name="nama" id="nama" /></td>
</tr>
<tr>
<td>Website</td>
<td><label for="textfield"></label>
<input type="text" name="website" id="website" /></td>
</tr>
<tr>
<td>Komentar</td>
<td><label for="textfield"></label>
<label for="textarea"></label>
<textarea name="pesan" id="pesan"></textarea></td>
</tr>
<tr>
<td> </td>
<td><label for="Submit"></label>
<input type="submit" name="Submit" value="Submit" id="Submit" />
<label for="label"></label>
<input type="reset" name="Submit2" value="Reset" id="label" /></td>
</tr>
</table>
<p>Komentar Lainnya : </p>
</form>
<?php
//konfigurasi koneksi
mysql_connect ("localhost","root","");
mysql_select_db ("db_komentar");
//inisialisasi tanggal
$tanggal = date ("Ymd");
//inisialisasi waktu
$time = date ("H:i:s");
//query untuk menambah data ke dalam tabel
$kueri = mysql_query ("INSERT INTO tb_komentar(nama,website,pesan,tanggal,time) values ('$_POST[nama]', '$_POST[website]', '$_POST[pesan]', '$tanggal','$time')");
//query untuk menampilkan data ke dalam tabel
$query = mysql_query ("SELECT * FROM tb_komentar ORDER BY time || tanggal DESC");
while ($d = mysql_fetch_array ($query))
{
$psn = $d['pesan'];
echo "<table>";
echo "<tr><td><b>$d[nama] : $psn</b></td></tr>";
echo "<tr><td><i>Website : $d[website]</i></td></tr>";
echo "<tr><td align=right>$d[time]: $d[tanggal]</td></tr></table><hr>";
}
?>
</body>
</html>
- next I will explain the function of the script above
- part of the program for connection between PHP with MySQL:

in the red column is the name of the database - now I will explain the section that serves to save comments that have been entered visitors to the database.

- hereinafter is a section to display back data that has been saved to database to web page.

- okay ,, comment field we have successfully created, then we try to run whether it is running as we want.
- run the program we have written above in your browser, write your file address as shown below.

if the image above appears, It means you have successfully created comment field - now we try to enter our comments on the form.

write the comment then we see whether to go into the database.
- now we see in the database whether the above comments have entered.

okay has succeeded, comments have entered into our database
- Please try by following the steps above carefully.
Curriculum
- Cara Membuat Fitur Minichat Pada Website Anda Menggunakan PHP-MySQL
- How to make website : booking bus tickets using PHP - MySQL
- How to create login form using PHP - MySQL
- How To Display Data From Your Database To Webpage using PHP-MySQL
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Hey @lapulga I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x