How to make comment box in php mysql?
How to make a comment box in php mysql?
How to Create Comment Box Using PHP in MySQL Database.
Database name:-combox
Database table name:-comt
image folder name:-img
Main.php: - In this file, users create forms where users filling their information in the text field and create a record.
Comment.php:- When the user fills all the required information and finally the user clicks on the button, the user can read the records from the database. All data is stored in the database.
View.php:- Help of this file is very useful because in this file users see their data as one or one record from database. To display data retrieved from MySQL database.
Delete.php :- This file is used to delete a record. It accepts an id parameter and deletes records with it. Once it executes the deleted query, it will redirect the user to the comment
button.css:- This file is used to design the button
You may also like
Database
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 ;
main.php
<!DOCTYPE html>
<html>
<head><title>comment with profile</title>
<link rel="stylesheet" type="text/css" href="button.css">
<style type="text/css">
input:focus::-webkit-input-placeholder{opacity:0;}
textarea:focus::-webkit-input-placeholder{opacity:0;}
.button{border:none;background:blue;color:white;font-size:25px; cursor: pointer;}
.chf{color:maroon;font-size:20px; text-align: center;border: ridge;
width: fit-content; background-color: #55e8ca; box-shadow: 9px 6px 13px 0px #0000007d;
}
</style>
</head>
<body>
<a href="view.php"class="bth">View or Delete</a><p>
<form method="POST"action="comment.php"enctype="multipart/form-data">
<div class="chf">
<tr>
<td>
Name:-  <input type="text" name="name"placeholder="Your Name"required><p>
</td>
</tr>
<tr>
<td>
Comment:-<textarea name="comment"placeholder="Write your comment"required></textarea><br><br>
</td>
</tr>
<tr>
<td>
    
Profile:- <input type="file" name="file"value='upload'required/><p>
</td>
</tr>
<tr><td><br>
      
<button class="button" name="upload"title="upload your profile">upload<div></button>
</td>
</tr>
</div>
</form>
</body>
</html>
comment.php
<?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);
}
?>
<!DOCTYPE html>
<html>
<head>
<style>body{background:#0202025e;}</style>
<link rel="stylesheet" type="text/css" href="button.css">
</head>
<body>
<a href='view.php'class="bth">View Or Delete</a><p>
<script>alert('successfully uploaded')</script>
</body>
</html>
view.php
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="button.css">
<style type="text/css">
a{text-decoration:none;border: none;color: #ad2525;
font-size: larger;}
img{border-radius:50%;}
</style>
</head>
<body>
<a href='main.php'class="bth">Back To Home</a><p>
<div style='background:#83d6d4;width: fit-content;box-shadow: 9px 6px 13px 0px #0000007d;'>
</body>
</html>
<?php
$conn=mysql_connect("localhost","root","","combox");
if(!$conn)
{
die(mysql_error());
}
mysql_select_db("combox");
$result=mysql_query("select *from comt");
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>";
echo"<td><img src='img/".$row['img']."'width='70px'height='50px'></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['comment']."</td>";
echo"<td><button><a href='delete.php?id=$row[id]'>Delete</button></a>";
echo"</tr>";
}
echo "</table>";
?>
delete.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("combox");
$id=$_GET['id'];
mysql_query("delete from comt where id=$id");
header("location:view.php");
?>
">
button.css
.bth{background:#04f7f7; border:1px groove;
color: white;padding: 3px;
margin: 3px;
font-size: larger;
text-decoration: none;box-shadow: 9px 6px 13px 0px #0000007d;}
Comments
Post a Comment