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

报告相同问题?

悬赏问题

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