-1

I am trying to implement a comment system, but it returns the post as many times the comment of that post exists.

Please help me with the code to solve out this.
Thank you.

The sample I have is like:

    <?php

include('connect.php');

?>

<form method="post">

Subject<br>
<input type="text" name="subject"><br><br>
Message<br>
<textarea name="text"></textarea>
<br>
<input type="submit" name="poster" value="Post">

</form>

<?php

if (isset($_POST['poster'])) {
    $subject=$_POST['subject'];
    $message=$_POST['text'];

    $post=mysql_query("insert into comment (titles, message) values ('$subject', '$message')");
    if ($post) {
        echo "Data got";
    }else{
        echo "Failed";
        echo mysql_error();
    }
}

$select=mysql_query("SELECT comment.id, comment.titles, comment.message, replies.id, replies.idno, replies.subject, replies.textfile from comment left JOIN replies ON comment.id=replies.id ;");


while ($row=mysql_fetch_array($select)) {

    echo "<b>".$row['titles']."</b><br>";
    echo $row['message']."<br>";
    echo "<a href=\"edit.php?id=$row[id]\">Reply</a><br>";
    echo "<font color='green'><ul>".$row['textfile']."</ul></font><br><br>";

}

?>

But it returns:

Result

Thank you.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • [Little Bobby](http://bobby-tables.com/) says [your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Even [escaping the string](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) is not safe! – Jay Blanchard May 16 '16 at 19:27
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 16 '16 at 19:27

1 Answers1

0

your code seem was wrong in this line:

$select=mysql_query("SELECT comment.id, comment.titles, comment.message, replies.id, replies.idno, replies.subject, replies.textfile from comment left JOIN replies ON comment.id=replies.id ;");

on left join , comment.id must compare with other replies table fields like replies.commentid for example the end of your query must be like this:

ON comment.id=replies.commentid;");
Hossein
  • 1,301
  • 1
  • 12
  • 23