How to make awesome stylish comment input box in PHP language for my website.
In this tutorial we are creating comment input box for websites into PHP scripting language. We are storing comments directly into MySQL database so website admin can assess them using PhpMyAdmin control panel. This forms are designed with custom style CSS code that makes the input files more big and gives hover effects. So here is the complete step by step tutorial for Create PHP comment box using MySQL database and Store entered comments into DB.
How to Create PHP comment box using MySQL database and Store entered comments into DB.
Code for comment.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Comment Box</title> <style> body{ margin:0px; font-family:Baskerville, 'Palatino Linotype', Palatino, 'Century Schoolbook L', 'Times New Roman', serif; } input[type=text], select { width: 100%; border-radius: 5px; margin: 7px 0; border: 1px solid #ccc; padding: 14px 18px; display: inline-block; box-sizing: border-box; } input[type=submit]:hover { background-color: #00a7d1; } textarea, select { width: 100%; border-radius: 5px; margin: 7px 0; border: 1px solid #ccc; padding: 14px 18px; display: inline-block; box-sizing: border-box; } input[type=submit] { width: 100%; border: none; color: white; padding: 14px 20px; background-color: #01c9fb; margin: 8px 0; cursor: pointer; border-radius: 4px; } </style> </head> <body> <table bgcolor="#f2f2f2" style="padding:50px" align="center"> <form action="" method="post"> <tr> <td> Name : </td><td><input type="text" name="name"></td> </tr> <tr> <td> Email : </td><td><input type="text" name="email"></td> </tr> <tr> <td> Website : </td><td><input type="text" name="website"></td> </tr> <tr> <td> Comment : </td><td><textarea name="comment" rows="6" cols="50"></textarea></td> </tr> <tr> <td><input type="submit" name="submit"></td></tr> </form> </table> <?php if(isset($_POST["submit"])) { //Including dbconfig file. include 'dbconfig.php'; $name = $_POST["name"]; $email = $_POST["email"]; $website = $_POST["website"]; $comment = $_POST["comment"]; mysql_query("INSERT INTO comment_table (name,email,website,comment) VALUES ('$name','$email','$website','$comment')"); echo '<center> Comment Successfully Submitted </center>'; } ?> </body> </html>
Code for dbconfig.php file.
<?php //This script is designed by Android-Examples.com //Define your host here. $hostname = "localhost"; //Define your database username here. $username = "root"; //Define your database password here. $password = ""; //Define your database name here. $dbname = "test"; $conn = mysql_connect($hostname, $username, $password); if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db($dbname, $conn); //This script is designed by Android-Examples.com ?>
Screenshot:
sahi hai
hmmm
This project is running fine.
I have gone through other project also…they are also good…
Nice job…..
Thanks Rahul.
Great
I need something like this
Ya
This is a good tutorial
i like it too ………….
Thank you for the code. its really works. nice
great post, very informativge just the answer i was looking for
Welcome jimmy .
brian
Hello
Is it mandatory to use PhpMyadmin for this comment box. Because I am using Netbeans IDE and I want to use either embedded Java database or an connecting with an external oracle SQL developer. Will it still work?
Yes Johan it will work.
Hello
My question is where is the code for displaying the comments on the page? You need to fetch them from the database and show them. Where have you done that?
Sally this tutorial is only to post comment, i will soon upload a new tutorial to show comments on page.
Thanks, please do it. I will wait.
Sure Sally , And thanks for visiting my website.
mysql_connect is deprecated so I will need to use mysqli_connent