如何在表单模式引导程序中从其他表传递值

时间:2019-05-11 04:53:13

标签: php bootstrap-modal html-select

我创建了一个模态表单来更新具有存储字段的记录,该字段具有一个选项,必须从另一个表中获取,但是如果数据库中已经存在存储数据,则显示现有数据。 我做了这段代码,但是它无法显示现有数据。 如果将“存储”的代码更改为:ABC,那么它可以显示数据库中的现有数据。

<?php
// to connect database
include '../connection/connect.php';
$query_storage = mysqli_query ($connect, "SELECT * from storage ORDER BY 
storages ASC");
?>

//code for modal bootstrap
<div id="add_data_Modal" class="modal fade">  
<div class="modal-dialog">  
<div class="modal-content">  
<div class="modal-header">  
<button type="button" class="close" data-dismiss="modal">&times;</button>  
                 <h4 class="modal-title">Reagent Detail Information</h4>  
</div>  
<div class="modal-body">  
<form method="post" id="insert_form">  
<label>Storage</label>  
<select class="form-control" name = "storage" id="storage" required >
<?php while($row = mysqli_fetch_assoc($query_storage)){?>
<option value="<?php echo $row['id_storage']; ?>">
<?php echo $row['storages']; ?></option>";
<?php }
?>
</select>
<br />  
<label>Min Stock</label>  
<input type="text" name="min_stock" id="min_stock" class="form-control" />
<br />  

<input type="hidden" name="reagent_id" id="reagent_id" />  
<input type="submit" name="insert" id="insert" value="Insert" class="btn btn-success" />  
</form>  
</div>  
<div class="modal-footer">  
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
</div>  
</div>  
</div>  
</div>  
<script>  
$(document).ready(function(){  
$('#add').click(function(){  
       $('#insert').val("Insert");  
       $('#insert_form')[0].reset();  

  });  
$(document).on('click', '.edit_data', function(){  
       var reagent_id = $(this).attr("id");  
       $.ajax({  
            url:"php/reagent_master/fetch.php",  
            method:"POST",  
            data:{reagent_id:reagent_id},  
            dataType:"json",  
            success:function(data){  
                 $('#storage').val(data.storages);
                 $('#min_stock').val(data.min_stock); 
                 $('#max_stock').val(data.max_stock); 
                 $('#reagent_id').val(data.id_reagent_master);  
                 $('#insert').val("Update");  
                 $('#add_data_Modal').modal('show');  
            }  
       });  
 });

1 个答案:

答案 0 :(得分:0)

按顺序从数据库中获取数据,然后在此存储中找到记录时显示错误消息。存储已经存在