Click here to Skip to main content
14,971,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<form action="" method="GET">
<?php
$sql = mysqli_query($con, "select * from blogs");
while($row = mysqli_fetch_array($sql)){
echo  '<img id="myImg" style="height: 400px; width: 800px; float: left;" src="pages/'.$row['url'].'" alt="'.$row['description']. '">';
echo '<br />';
echo '<p >'.$row['description']. '</p>';
echo '<br />';
echo '<br />';
echo '<br />';
$del = $row['id'];
$sql1 = mysqli_query($con, "SELECT * FROM blog_comments WHERE id= '$del'");
while($row1 = mysqli_fetch_array($sql1)){
echo '<p>   Posted by: ' .$row1['username'] .'<p>';
echo '<p>     ' .$row1['comment'] .'<p>';
echo "<th><a href=\"blog.php?delete={$row1['user_id']}\">delete</a></th>";
echo '<br />';
}**echo '<form method="GET">';
echo '<input type="hidden" name="id" value="'.$row['id'].'">';
echo '<h2>Comments</h2>';
echo '<label>Username</label><br />';
echo '<input type="text" name="username">';
echo '<br />';
echo '<label>Comment :</label><br />';
echo '<textarea name="comment" id="comment" width="300px"></textarea><br />';
echo '<button name="submit1">Submit</button>';
echo '</form>';
}
}
?>
</form>


What I have tried:

Comment of each post using php. Hi i need help ? i just want to insert a comment on each post just like on facebook but i have problem on my code. im hardly analyzing code.. the process is the comment only it insert into the last post of my blog. is anybody knows how to insert comments into the desire post that i want to comment
Posted
Updated 7-Oct-17 8:04am

1 solution

PHP
$sql1 = mysqli_query($con, "SELECT * FROM blog_comments WHERE id= '$del'");

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900