Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用select选项从数据库中获取数据,以便在inputbox中显示_Javascript_Php_Html_Mysql - Fatal编程技术网

Javascript 如何使用select选项从数据库中获取数据,以便在inputbox中显示

Javascript 如何使用select选项从数据库中获取数据,以便在inputbox中显示,javascript,php,html,mysql,Javascript,Php,Html,Mysql,用于从数据库获取数据的文件 public function getOneByName($name){ try{ $link = DB_Helper::createMySQLConnection(); $query = "Select * From vendor Where vendor_name=?"; $stmt = $link->prepare($query); $stmt->bindValue(1,$name,PDO::PAR

用于从数据库获取数据的文件

public function getOneByName($name){
try{
    $link = DB_Helper::createMySQLConnection();
    $query = "Select * From vendor Where vendor_name=?";
    $stmt = $link->prepare($query);
    $stmt->bindValue(1,$name,PDO::PARAM_STR);
}catch(PDOException $e){
    $link->rollBack();
    $e->getMessage();
    die();
}
$link =null;
return $stmt;
}
单击“选择选项”时,如何将数据显示到输入框中

<label>ID</label><input type="text" id="id_vendor" name="id_vendor" /> <br/>
<label>Email</label><input type="text" id="email" name="email" /> <br/>
<label>Date</label><input type="date" id="start_date" name="start_date" /> <br/>

<select name="type" class="form-control">
<option  selected="type" disabled=""> </option>
<?php echo $vendor ?>
</select>

<label>Date</label><input type="date" id="date_done" name="date_done" />
ID
电子邮件
日期
日期

在head中加载jquery:

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
Php:

<select name="type" id="type" class="form-control">
$(document).on('change','#type',function(e) {
  e.preventDefault();
    $.ajax({
      url: '#Call funtion from here#',
      type: 'POST',
      dataType : 'json',
      data: {type:$('#type').val()},
      success: function(response) {
        if(response.status == true) {
          // Check data using console log for debug
          console.log(response.data);

          // Set data
          $('#id_vendor').val(response.data....);
        }
      }
    });
});
return json_encode([
  'status' => true
  'data' => $stmt
]);