简体   繁体   中英

How to pass value from other table in form modal bootstrap

I created a modal form to update the record with storage field that has an option and have to be taken from another table but if storage data already exist in the database then show existing data. I did this code but it cannot show existing data. If I change the code for "storage" to : ABC then it can show existing data in database.

<?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');  
            }  
       });  
 });

get data from database by stroge and then if record found with this storage show your error message. Storage already exists

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM