Sensation Energy

Tutorials


Content


Advertising


Funtion 7 Comments System






What is Funtion 7 Comments System

Funtion 7 comments system is system form comment. and replays. Comments system allows us to comment indefinitely and to respond to our comments.

It is used by first creating a database in PHPMyAdmin and pasting the previously copied database. Then place the folder in the web server folder and run it at the address as an example LOCALHOST. If you want to integrate with your blog, form, ... then put it in the folder where yours is the form, blog, news, .. and use it

Index (index.php)


<?php
require 'conn.php';
$sql = "SELECT * FROM comm WHERE p_id=0";
$result = mysqli_query($konekcija,$sql);
while($row=mysqli_fetch_assoc($result)){
$k_id = $row['k_id'];
$name = $row['name'];
$msg = $row['msg'];
$date = $row['date'];
$p_id = $row['p_id'];
$sql2 = "SELECT * FROM comm WHERE p_id='$k_id'";
$result2 = mysqli_query($con,$sql2);
$x= mysqli_num_rows($result2);
?>
<h1>Comments:</h1>
<ul>
<li><h2>Name: <?php echo $name; ?></h2></li>
<li><h2>Comment: <?php echo $msg; ?></h2></li>
<li><h2>Date: <?php echo $date; ?></h2></li>
</ul>
<h1>Replay:</h1>
<h3>Sum replay: <?php echo $x; ?></h3>
<div align="center">
<input type="button" class="btn-10" name="answer" value="Show repaly" onclick="showDiv('div1<?php echo $k_id; ?>')" />
<input type="button" class="btn-9" name="answer" value="Add repaly" onclick="showDiv1('div2<?php echo $k_id; ?>')" />
</div>
<div id="div1<?php echo $k_id; ?>" style="display:none;" class="card">
<?php
$sql1 = "SELECT * FROM comm WHERE p_id='$k_id'";
$result1 = mysqli_query($con,$sql1);
while($row1=mysqli_fetch_assoc($result1)){
$name = $row1['name'];
$msg = $row1['msg'];
$date = $row1['date'];
?>
<ul>
<li>Name: <?php echo $name; ?></li>
<li>Comment: <?php echo $msg; ?></li>
<li>Date: <?php echo $date; ?></li>
</ul>
<?php } ?>
</div>
<div id="div2<?php echo $k_id; ?>"  style="display:none;"  class="answer_list">
<form action="ubacivanje.php" id="comment_form" method="post" enctype="multipart/form-data">
<input type="hidden" value="<?php echo $k_id; ?>" name="p_id"/>
<div class="form">
<lable><h2>Name</h2></lable>
<input type="text" name="name" class="form-input">
</div>
<div class="form">
<lable><h2>Text</h2></lable>
<textarea name="msg" rows="5" cols="20" class="form-input"></textarea>
</div>
<input type="submit" name="add" value="Submit Comment">
</form>
<?php } ?>

Add comment (add_c.php)


<?php
require 'conn.php';
if(isset($_POST['add'])){
$name = $_POST['name'];
$msg = $_POST['msg'];
$sql = "INSERT INTO comm (name,msg,p_id) VALUES ('{$name}','{$msg}','0')";
$result = mysqli_query($konekcija,$sql);
header("Location: index.php");
echo "Add is good.";
}
?>

Add repaly (add_r.php)


<?php
require 'conn.php';
if(isset($_POST['add'])){
$name = $_POST['name'];
$msg = $_POST['msg'];;
$p_id = $_POST['p_id'];
$sql = "INSERT INTO comm (name,msg,p_id) VALUES ('{$name}','{$msg}','{$p_id}')";
$result = mysqli_query($konekcija,$sql);
header("Location: index.php");
echo "Add is good.";
}
?>


conn.php


<?php
$server = "localhost";
$user = "root";
$password = "root";
$base = "example";
$con = mysqli_connect($server, $user, $password, $base);
?>

comm - database


CREATE TABLE `comm` (
`k_id` int(20) NOT NULL,
`name` varchar(200) NOT NULL,
`msg` varchar(200) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`p_id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `comm`
ADD PRIMARY KEY (`k_id`);
ALTER TABLE `comm`
MODIFY `k_id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

JS script

Insert JS script in index.php page after </form> <?php } ?>


<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script>
function showDiv(Div) {
var x = document.getElementById(Div);
if(x.style.display=="none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function showDiv1(id) {
var x = document.getElementById(id);
if(x.style.display=="none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>