How To Add Comment Field On Your Website Using PHP-MySQL

in #utopian-io8 years ago (edited)

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.
    image.png
    function so that we can create a database

  • then open your browser type ``` http: // localhost / xampp / `` `in the search field of your browser.
    image.png
    choose phpMyAdmin

  • create a database like the image below through the MySQL GUI
    image.png
  • 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>&nbsp;</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:
    image.png
    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.
    image.png
  • hereinafter is a section to display back data that has been saved to database to web page.
    image.png

  • 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.
    image.png
    if the image above appears, It means you have successfully created comment field
  • now we try to enter our comments on the form.
    image.png
    write the comment then we see whether to go into the database.

  • now we see in the database whether the above comments have entered.

    image.png
    okay has succeeded, comments have entered into our database

  • Please try by following the steps above carefully.

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Coin Marketplace

STEEM 0.05
TRX 0.32
JST 0.082
BTC 64836.50
ETH 1769.77
USDT 1.00
SBD 0.42