duanche5149 2016-08-19 04:20
浏览 22
已采纳

用户在PHP中键入重复键时自动显示文本

I need some help with my project, when i type in textbox (primary key - textbox), if it is duplicated key in mysql, it will show text next to textbox like this (not click button, it will show auto when i type: ABC12444 -> this record is exist in system):

enter image description here

My code:

 $idcustomer = $_POST['txtIDCus'];
 $result = $mysqli->query("SELECT * FROM customer where id='$idcustomer' ");
    if ($result->num_rows > 0) {
        $errMsg="Key exist in system";
    }

Simple HTML Code

<b>ID Customer:</b>
<input type="text" id="txtIDCus" name="txtIDCus" width="100" placeholder="Type ID Customer" size="40" class="form-control" maxlength="70"/> <br />

I try to show my stuck, hope you help me. Thanks!

  • 写回答

1条回答 默认 最新

  • douturan1807 2016-08-19 04:33
    关注

    You can do this using jquery.. I hope this helps..

    HTML

    <input type="text" id="key" /> <span id="key-result"> </span>
    

    JavaScript

    $("#key").on("input", function() {
            var key = this.value;
            //you can skip using timeout just call check_key_ajax(key);
            x_timer = setTimeout(function(){check_key_ajax(key)}, 1000);            
        });
    
    function check_key_ajax(key){            
            $.post('checkKey.php', {'Key':key}, function(data) {$("#key-result").html(data);});            
        }
    

    Checker.php

        if(isset($_POST["Key"]))
        {
        $idcustomer = $_POST["Key"];
        $result = $mysqli->query("SELECT * FROM customer where id='$idcustomer'");
        if ($result->num_rows > 0) {
            $errMsg="Key exist in system";
            echo $errMsg;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置