我想实现一个评论系统,但它返回多少次该帖子的评论存在的帖子。评论系统显示单个帖子的多个帖子(php mysql)
请帮我解决这个问题的代码。
谢谢。
我拥有的样本是这样的:
<?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>";
}
?>
但它返回:
谢谢。
[小博](http://bobby-tables.com/)说:[你的脚本是在对SQL注入攻击的风险。(http://stackoverflow.com/questions/60174/how-可以-I-防止-SQL注入功能于PHP)。即使[转义字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –
请[停止使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [这些扩展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中删除。了解[编写](http://en.wikipedia.org/ wiki/Prepared_statement)语句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –