我尝试了很多方法来使用 php jquery,ajax 为我的网站构建评论系统,但是在数据库中插入评论时出现问题我的代码有什么问题
html
<div id="comments" class="cmt">
<form method="post" >
<textarea class="textinput"id="comment" rows="5" name="comments" placeholder="Comment Here......"></textarea><br>
<button type="button" id="comq"name="compost" class="butn2" >post comment</button>
</form>
</div>
jQuery 和 ajax
$(document).ready(function()
{
$("#comq").click(function() {
var comment=$("#comment").val();
$.ajax({
cache:false,
type:"post",
url:"pnf.php",
data:{comments:comment},
success:function(data)
{
$('.cmt').html(data);
}
});
});
});
PHP (pnf.php)
if(isset($_POST["compost"])){
$comment=$_POST['comments'];
{
$reslt_user= mysqli_query($connection,"SELECT * FROM tbl_users,`queries` where id='".$_SESSION['id']."' AND qid= '".$qid."' ");
$row_lat_lng= mysqli_fetch_array($reslt_user);
$stmt = mysqli_query($connection,"INSERT INTO comments set uid='".$_SESSION['id']."',comments='".$comment."',reply='".$reply."' ,
qid= '".$qid."' ");
}
if($stmt)
{
echo "hello world";
}
}
试试这个:
HTML
<div id="comments" class="cmt">
<textarea class="textinput" id="comment" rows="5" name="comments" placeholder="Comment Here......"></textarea><br>
<button type="button" id="comq"name="compost" class="butn2" >post comment</button>
</div>
对于 PHP:
if(isset($_POST["comments"])){
$comment = $_POST['comments'];
$reslt_user= mysqli_query($connection,"SELECT * FROM tbl_users,`queries` where id='".$_SESSION['id']."' AND qid= '".$qid."' ");
$row_lat_lng= mysqli_fetch_array($reslt_user);
$stmt = mysqli_query($connection,"INSERT INTO comments set
uid='".$_SESSION['id']."',comments='".$comment."',reply='".$reply."' ,
qid= '".$qid."' ");
if($stmt)
{
echo "hello world";
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句