douzhao2047 2013-07-25 11:27
浏览 40
已采纳

启用默认禁用按钮 - PHP,HTML,jQuery

I really need help.

I am trying to have a setup wherein an admin could enable a client's button that is disabled by default.

So far, I have this code below for the admin. It updates the value column (0 by default) in the button table in the database. And this part is successful.

<input name="enable1"  type="submit"   id="button" value="Enable Button" />


<?php
    if(isset($_POST['enable1'])){           
    mysql_query("UPDATE button SET value = '1' WHERE cat_no = 'cat1'"); }
?>

And the code for the user is written below. My plan is that, when the admin updates the column value into 1, the code below will echo the enabled button, as by the default, the button is disabled.

And this part is a failure, it does not enable the disabled button. And I noticed, that the first echo in the if statement doesn't work, the only thing that is working is the echo in the else statement where the button is disabled.

<?php 

    $sql="SELECT value FROM button WHERE cat_no = 'cat1'";

$result=mysql_query($sql) or die(mysql_error());

if ($result == '1'){
    echo '<input name="enable2"  type="submit" class="inputDisabled"        

        id="button"  value="Proceed to Next Category" />' ;}

else {

    echo '<input name="enable2"  type="submit" class="inputDisabled"        

        id="button"  disabled="disabled"  value="Proceed to Next Category" />';}                            
 ?>

I also tried to search for alternatives like jQuery. But I can't make it work. And if possible, when the admin clicks the button, the user's page will refresh automatically.

Please help. I really need guidance. Thank you.

  • 写回答

2条回答 默认 最新

  • ds3422222222 2013-07-25 11:42
    关注

    Well, Try this :

    <?php 
    
        $sql="SELECT value FROM button WHERE cat_no = 'cat1'";
    
    $result=mysql_query($sql) or die(mysql_error());
    $result= mysql_result($result,0,"value"); // I added this line
    if ($result == '1'){
        echo '<input name="enable2"  type="submit" class="inputDisable"        
    
            id="button"  value="Proceed to Next Category" />' ;}
    
    else {
    
        echo '<input name="enable2"  type="submit" class="inputDisabled"        
    
            id="button"  disabled="disabled"  value="Proceed to Next Category" />';}                            
     ?>
    

    Is there only one client ? If not how will you check which client's button is enabled and which is not ?

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

报告相同问题?

悬赏问题

  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致
  • ¥15 禅道二次开发编辑版本,上传不了发行包