Javascript [html、php、mysql]如何使用输入或按钮在当前行的基础上动态获取上一行,并在文本区域中显示
我现在正在构建一个论坛,我将有一个带有“编辑”按钮的导航栏,供用户编辑他们以前的评论Javascript [html、php、mysql]如何使用输入或按钮在当前行的基础上动态获取上一行,并在文本区域中显示,javascript,php,html,mysql,Javascript,Php,Html,Mysql,我现在正在构建一个论坛,我将有一个带有“编辑”按钮的导航栏,供用户编辑他们以前的评论 <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div> <ul class="nav navbar-nav navbar-left"> <li><
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<div>
<ul class="nav navbar-nav navbar-left">
<li><a href="#quest"> Post a Question</a></li>
<li><a href="#edit"> Edit comment</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="userprofile.php" ><span class="glyphicon glyphicon-user"></span> <?php echo $username;?></a></li>
<li><a href="logout.php"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
</ul>
</div>
</div>
下面是我如何在页面上显示之前发布的所有评论,但我不知道这是否有帮助
<div class="panel-body">
<?php
$id = $_GET['post_id'];
$sql = mysql_query("SELECT * from tblpost as tp join category as c on tp.cat_id=c.cat_id where tp.post_Id='$id' ");
if($sql==true){
while($row=mysql_fetch_assoc($sql)){
extract($row);
if($user_Id==009){
echo "<label>Topic Title: </label> ".$title."<br>";
echo "<label>Topic Category: </label> ".$category."<br>";
echo "<label>Date time posted: </label> ".$datetime;
echo "<p class='well'>".$content."</p>";
echo "<label>Posted By: </label> Admin";
}else{
$sel = mysql_query("SELECT * from tbluser where user_Id='$user_Id' ");
while($row=mysql_fetch_assoc($sel)){
extract($row);
echo "<label>Topic Title: </label> ".$title."<br>";
echo "<label>Topic Category: </label> ".$category."<br>";
echo "<label>Date time posted: </label> ".$datetime;
echo "<p class='well'>".$content."</p>";
echo '<label>Posted By: </label>'.$fname.' '.$lname;
}
}
}
}
?>
我建议您从mysql
更新到mysqli
,因为mysql
已贬值。另外,如果不清除/检查$id
变量而将其放入SQL查询,则会使数据库面临SQL注入的风险。为了安全起见,我知道real_escape_string()和strip_tag()函数,但这不是我现在的重点,因为它将仅在我的本地主机中。。。
<div class="my-quest" id="edit">
<div>
<h3>Edit Comment</h3>
<form method="POST" action="editcomment.php">
<?php
$postid= $_GET['post_id'];
$comment = mysql_query("SELECT * from tblcomment as c join tbluser as u on c.user_Id=u.user_Id where post_Id='$postid' and comment_Id in ( select max(comment_Id) from tblcomment)");
$rowedit=mysql_fetch_assoc($comment)
?>
<textarea type="text" class="form-control" name="editcommenttxt"><?php echo $rowedit['comment']?></textarea><br>
<input type="hidden" name="editpostid" value="<?php echo $_GET['post_id']; ?>">
<input type="hidden" name="edituserid" value="<?php echo $_SESSION['user_Id']; ?>">
<input type="submit" name="editcomment" class="btn btn-success pull-right" value="Edit">
</form>
<br>
<hr>
<a href="" class="pull-right">Close</a>
</div>
</div>
<?php
include "../functions/db.php";
if(isset($_POST['editcomment'])){
extract($_POST);
$check = mysql_query("select max(comment_Id) as maxid from tblcomment where user_Id = '$edituserid'");
$check2 = mysql_fetch_assoc($check);
$sql = "Update tblcomment set comment='$editcommenttxt' where post_Id = '$editpostid' and comment_Id = '".$check2['maxid']."'";
$update=mysql_query($sql);
if($update==true) {
echo '<script language="javascript">';
echo 'alert("Post Successfully")';
echo '</script>';
echo '<meta http-equiv="refresh" content="0;url=content.php?post_id='.$editpostid.'" />';
} else {
echo "Sorry error occur, cannot edit post!";
}
}
?>