duanbu9345 2016-12-31 12:09
浏览 34
已采纳

1单击然后禁用 - PHP

I have been looking around on the forum and tried everything but I cant get my button to disable after clicking it, I just started using php and this is one of my first projects. Its a like and dislike system. Does anyone know the awnser? when you press a like button or dislike button I want both buttons to be disabled.

<!--Like System-->
<center>

<?php

$sql = "SELECT * FROM likes";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        ?>  <h1 class="lcount"><?php    echo $row["average"];?> <span class="glyphicon glyphicon-signal"></span></h1></br><?php

    }
} else {
    echo "0 results";
}
?>

<?php

$sql = "SELECT * FROM likes";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        ?>  <h1 class="lcount"><?php    echo $row["like"];?> 
        <span style="color: green;"class="glyphicon glyphicon-thumbs-up"></span></h1></br>

<?php
    }
} else {
    echo "0 results";
}
?>

<?php

$sql = "SELECT * FROM likes";
$result = mysqli_query($con, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        ?>  <h1 class="lcount"><?php    echo $row["dislike"];?> 
        <span style="color: red;" class="glyphicon glyphicon-thumbs-down"></span></h1>

<?php
    }
} else {
    echo "0 results";
}
?>

<?php

if(isset($_POST['like'])){

    $sql = "UPDATE `likes` SET `like` = `like` + 1 , `average` = `average` + 1";


    if (mysqli_query($con, $sql)) {
    } else {
        echo "Error updating record: " . mysqli_error($con);
    }
}
?>

<?php

if(isset($_POST['dislike'])){

    $sql = "UPDATE `likes` SET `dislike` = `dislike` + 1 , `average` = `average` - 1";


    if (mysqli_query($con, $sql)) {
    } else {
        echo "Error updating record: " . mysqli_error($con);
    }
}
?>

    <form type="#" method="post">
        <button name="like" type="submit" class="btn btn-success">
            <span class="glyphicon glyphicon-thumbs-up"></span></button>

        <button name="dislike" type="submit" class="btn btn-danger">
            <span class="glyphicon glyphicon-thumbs-down"></span></button>
    </form>
</center>
<!--Like System END-->
  • 写回答

2条回答 默认 最新

  • dotws86260 2016-12-31 12:25
    关注

    If you want to only PHP use like this:

    <?php
    
    $status = 'enabled';
    
    if (isset($_POST['like'])) {
        $status = 'disabled';
    }
    
    
    ?>
    
    <form type="#" method="post">
        <button name="like" type="submit" class="btn btn-success" <?=$status?>>
                    Button is <?=$status?>
        </button>
    </form>
    

    You can use Jquery like this:

    https://jsfiddle.net/y4qLew3s/1/

    Updated:

    I updated. It works with like or dislike button:

    https://jsfiddle.net/y4qLew3s/3/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀