我看过代码,但我似乎不知道问题出在哪里
让我删除所有必需的代码,以便任何人都可以提供帮助
if($_POST['like_id']){
$like_id = $_POST['like_id'];
$like_id = mysql_escape_string($like_id);
$id = $_SESSION['username'];
$qry = mysql_query("SELECT user_id FROM user WHERE username='$id'");
$chk = mysql_fetch_array($qry);
$uid = $chk['id'];
$query = mysql_query("SELECT like FROM topic WHERE id='$like_id'");
while($out = mysql_fetch_array($query)){
$like = $out['like'];
}
$qry = mysql_query("SELECT * FROM likes WHERE topic_id='$like_id' AND user_id='$uid'");
$count = mysql_num_rows($qry);
if($count == 0){
$new_like = $like+1;
$query = "UPDATE topic SET like='$new_like' WHERE topic_id='$like_id'";
$qu = mysql_query($query);
$query = mysql_query("INSERT INTO likes(user_id,topic_id) VALUES('$uid','$like_id')");
echo $like." likes";
}else{
echo "<script language=javascript>alert('you already LIKE this message !!')</script>";
echo "$like";
}
}
而html部分只是like按钮的标签
<li><a href="" id="'. $output['id'] .'" class="like_button"><i class="icon-heart" style="margin-top:3px;"> </i></a><span class="like_show"'. $output["id"] .'>Like</span></li>
然后是 jquery/ajax 部分
<script>
$(function(){
$(".like_button").click(function(){
var like_id = $(this).attr("id");
var datas = "like_id="+ like_id;
$(".like_show"+like_id).fadeIn(200).html('<img src="ajax-loader.gif" />');
$ajax({
type: "POST",
url: "../welcome.php",
data: datas,
cache: false,
success: function(html){
$(".like_show"+like_id).html(html);
}
});
return false;
});
});
Welcome.php 文件位于 header.php 文件之前的 1 文件夹。