donkey199024 2013-05-26 15:33
浏览 38

jquery / ajax“喜欢”按钮不起作用

i have looked at the code but i can't seem to know where the problem is from

lemme drop all the required code so anybody could help

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";
                 }

            }

and the html part just the tag of the like button

<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>

and then the jquery/ajax part

<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;
    });
});

the welcome.php file is located 1folder before the header.php file..

  • 写回答

2条回答 默认 最新

  • dongyu3967 2013-05-26 15:35
    关注

    Change

    $like_id = mysql_escape_string($like_id);
    

    to

    $like_id = mysql_real_escape_string($like_id);
    

    You should also avoid using mysql_* functions, and instead use PDO

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测