How to create simple comment box in php ?

How to create simple comment box in php?
Overview
Database name:-combox

Database table name:-comt

image folder name:-img

Main.php — In this file, the user creates a form where the user filling their information in the text filed and creates a record.
Comment.php - When a user fills in all required information and finally user clicks on button then user can read the record from a database. All the data will be stored in the database.

View.php — The help of this file is very useful because in this file users view their data as a single or single record from the database. Will display the data retrieved from the MySQL database.

You may also like

Delete.php — This file is used for deleting a record. It accepts an id parameter and deletes the record with it. Once it executes the delete query it will redirect the user to the comment.php


How to create a simple comment box in PHP?

Create Database combox and create table comt

CREATE TABLE IF NOT EXISTS `comt` ( `id` int(8) NOT NULL AUTO_INCREMENT, `name` varchar(110) NOT NULL, `comment` text NOT NULL, `img` varchar(50) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;


Dumping data for table `comt`

INSERT INTO `comt` (`id`, `name`, `comment`, `img`) VALUES (13, 'marco', 'How are you friend?', 'Dont-Angry.jpg'), (14, 'penso', 'How to make comment box in php?', 'magnifying2.jpg'), (15, 'diegon', 'Thank for providing this knowledge.', 'ask-me.jpg');

Create a file
 main.php
comment box input filed
main.php file


<html>
<head><title>comment with profile</title></head> <body> <a href='view.php'>View or Delete</a><p> <form method="POST"action="comment.php"enctype="multipart/form-data"> Name:-<input type="text" name="name"required><br> Comment:-<textarea name="comment"></textarea><br><br> Img:-<input type="file" name="file"value='upload'/><p> <button name="upload">upload</button> </form> </body> </html>


comment.php

<?php

 //require'view.php';

 if(isset($_POST['upload']))

 {

 $conn=mysql_connect("localhost","root","","combox");

 if(!$conn)

 {

 die('could not connect'.mysql_error());

 }

 mysql_select_db("combox");



 $name=$_POST['name'];

 $file_name=$_FILES['file']['name'];

 $tmp_name=$_FILES['file']['tmp_name'];

 $comment=$_POST['comment'];

 echo'<hr>';

 mysql_query("insert into comt(name,comment,img)values('$name','$comment','$file_name')")or die(mysql_error()); move_uploaded_file($tmp_name,"img/".$file_name);

 mysql_close($conn);

 //header('location:comment.php');

 echo"<a href='view.php'>View or Delete</a><br>";

 echo"<a href='Comment.php'>Back To Home</a>";

 }

 ?>



view.php file


<style> img{border-radius:50%;border: 1px solid #596094} </style> //view.php <?php //include'comment.php'; $conn=mysql_connect("localhost","root","","combox"); if(!$conn) { die(mysql_error()); } mysql_select_db("combox"); $result=mysql_query("select *from comt"); echo"<a href='main.php'>Back To Home</a><p>"; echo"<table border='1'width='auto'><tr> <th>Id</ih> <th>Profile</th> <th>Name</td> <th>Comment</td> <th>Delete</th> <tr>"; while ($row=mysql_fetch_array($result)) { echo"<tr>"; echo "<td>".$row['id']."</td>";# code... echo"<td><img src='img/".$row['img']."'width='70px'height='50px'></td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['comment']."</td>"; echo"<td><a href='delete.php?id=$row[id]'>delete</a>"; //echo "<td><img src='img/'width='50px';></td>"; echo"</tr>"; } echo "</table>"; ?>


delete.php file

<?php
mysql_connect("localhost","root",""); mysql_select_db("combox"); $id=$_GET['id']; mysql_query("delete from comt where id=$id"); header("location:view.php"); ?>

Comments