Php 单击“评论”按钮后复制消息
谁能解释一下为什么我收到的是重复的信息而不是一条? 如何更改代码,以便在键入注释并按下注释按钮时,仅显示一条消息而不是重复的消息!当我有一个评论框时,它不会显示重复的评论,但如果我有多个评论框,它就会开始复制 COMMENT.INC.PHP 页面代码Php 单击“评论”按钮后复制消息,php,Php,谁能解释一下为什么我收到的是重复的信息而不是一条? 如何更改代码,以便在键入注释并按下注释按钮时,仅显示一条消息而不是重复的消息!当我有一个评论框时,它不会显示重复的评论,但如果我有多个评论框,它就会开始复制 COMMENT.INC.PHP 页面代码 <?php date_default_timezone_set('America/Los_Angeles'); include 'comment.inc.php'; include("connection.php"
<?php
date_default_timezone_set('America/Los_Angeles');
include 'comment.inc.php';
include("connection.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="comment.css" rel ="stylesheet">
</head>
<body>
<?php
$sql="Select * from tbl_images";
$result=mysqli_query($connection,$sql);
while ($row=mysqli_fetch_array($result)) {
?>
<img src="images/<?php echo $row['images_name'] ?>" width="200px" height="200px">
<?php
echo "<form method ='POST' action ='".setComments($con)."'>
<input type ='hidden' name ='uid' value='unknown'>
<input type ='hidden' name ='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='message'></textarea>
<button type ='submit' name='commentSubmit'>Comment</button>
</form>";
}
getComments($con);
?>
</body>
</html>
也许你提交的是你所有的表格,而不是一张。。 检查您的数据库,以便了解每条消息的img信息。
如果您有其他类似javascript的代码,您应该发布它。是否使用ajax/jQuery提交表单?如果是这样的话,你也应该发布javascript。使用echo和exit一步一步地调试你自己的代码…。你的脚本有可能会看到使用过程中发生了什么。你正在做的是从注释中选择*。也许你应该将该查询限制为特定用户的注释,即从注释中选择*,其中uid=?感谢回复,但是我的评论是重复的!如果我只使用一个注释框和一个注释按钮,它将只在数据库上显示一条注释。然而,假设我有三个评论框,在上图中给出。当我在其中一个框上写评论并按下按钮时,它将在我的数据库中复制另外两个确切的评论。当我取出getComments$con;再试一次,它仍然有同样的问题!这是一个评论,而不是一个答案。请不要发表评论作为答案,人们往往会对此投反对票。你只需要加50分就可以对任何事情发表评论,在那之前,你只需要坚持问得很好、不需要澄清的问题
<?php
date_default_timezone_set('America/Los_Angeles');
include 'comment.inc.php';
include("connection.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="comment.css" rel ="stylesheet">
</head>
<body>
<?php
$sql="Select * from tbl_images";
$result=mysqli_query($connection,$sql);
while ($row=mysqli_fetch_array($result)) {
?>
<img src="images/<?php echo $row['images_name'] ?>" width="200px" height="200px">
<?php
echo "<form method ='POST' action ='".setComments($con)."'>
<input type ='hidden' name ='uid' value='unknown'>
<input type ='hidden' name ='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='message'></textarea>
<button type ='submit' name='commentSubmit'>Comment</button>
</form>";
}
getComments($con);
?>
</body>
</html>