在键盘文本字段上搜索数据库,然后检索其他文本字段上的数据

时间:2018-05-08 03:19:27

标签: php ajax mysqli autocomplete onkeyup

请帮帮我!我想通过输入客户电话号码进行搜索(在键盘上),然后它将从数据库中检索客户名称和电子邮件。Here my example form

<html>
<head>
<script type="text/javascript">

      $(function(){
          $(".cust_phone").keyup(function() {
          var cust_name = $(this).val();
          var cust_email = $(this).val();
          var dataString = 'cust_phone='+cust_name+cust_email;
          if(cust_name!='' && cust_email!='') {
            $.ajax({
              type: "POST",
              url: "customer_info.php",
              data: dataString,
              cache: false,
              success: function(html) {
                var data = html.split['|'];
                var cust_phone = data[0];
                var cust_name = data[1];
                var cust_email = data[2];
                $("#cust_phone").val(cust_phone);
                $("#cust_name").val(cust_name);
                $("#cust_email").val(cust_email);
              }
            });
          }
          return false;
        });

</script>
</head>

<body>

  <input type="text" name="cust_phone" id="cust_phone">
  <input type="text" name="cust_name" id="cust_name">
  <input type="text" name="cust_email" id="cust_email">

</body>
</html>

这是第一个文件(cutomer_form.php)

<?php

$cust_phone= $_POST['cust_phone'];

$query = mysql_query("SELECT DISTINCT cust_phone
  FROM rent WHERE cust_phone LIKE '$search'");

// $result = mysql_query("SELECT DISTINCT cust_phone
//   FROM rent WHERE cust_phone = '$search'");

$data = mysql_fetch_assoc($query);

$cust_name = $data['cust_name'];
$cust_phone = $data['cust_phone'];
$cust_email = $data['cust_email'];

echo $cust_phone .'|'. $cust_name.'|'.$cust_email;

?>

这是第二个文件(customer_info.php)

0 个答案:

没有答案