问题描述
< div class =modal fade validateid =modal-6>
< div class =modal-dialog>
< div class =modal-content>
< div class =modal-header>
< button type =buttonclass =closedata-dismiss =modalaria-hidden =true>& times;< / button>
< h4 class =modal-title>编辑广告< / h4>
< label class =idhere><?php echo $ id;?>< / label>
< / div>
<?php $ sel = $ d-> select('advertisements','ad_id = 12');
while($ result = mysqli_fetch_assoc($ sel)){
?>
< div class =modal-body>
< div class =row>
< div class =form-group col-md-6>
< label class =control-label>标题< / label>
< input class =form-controlvalue =<?php echo $ result ['title'];?> name =advertise_titledata-validate =requireddata-message-required =请输入标题placeholder =输入标题type =text>
< / div>
< div class =form-group col-md-6>
< label class =control-label> URL< / label>
< input class =form-controlname =advertise_urlvalue =<?php echo $ result ['url'];?> data-validate =requireddata-message-required =Please Enter URLplaceholder =Enter URLtype =text>
< / div>
< / div>
< div class =row>
< div class =col-md-12>
< div class =form-group no-margin>
< label for =descriptionclass =control-label>说明< / label>
< textarea class =form-control autogrowid =descriptionname =advertise_descplaceholder =描述关于查询的描述>
<?php echo trim($ result ['description']); ?>
< / textarea>
< / div>
< / div>
< / div>
< div class =row>
< div class =form-group col-md-6>
< label class =control-label>图片上传< / label>
< div>
< div class =fileinput fileinput-newdata-provide =fileinput>
< div class =fileinput-new thumbnailstyle =width:200px; height:150px;数据触发器= 的FileInput >
< img src =<?php echo $ result ['photo'];?>>
<! - < img src =images / thumbnail.jpegalt =...> - >
< / div>
< div class =fileinput-preview fileinput-exists thumbnailstyle =max-width:200px; max-height:150px>< / div>
< div>
< span class =btn btn-white btn-file>
< span class =fileinput-new>选择图片< / span>
< span class =fileinput-exists>更改< / span>
< input type =filename =advertise_photoaccept =image / *>
< / span>
< a href =#class =btn btn-orange fileinput-existsdata-dismiss =fileinput>删除< / a>
< / div>
< / div>
< / div>
< / div>
< / div>
< div class =row>
< div class =form-group col-md-6>
< label class =control-label>有效标记< / label>
< input type =checkbox>
< / div>
< / div>
< / div>
< div class =modal-footer>
< button type =buttonclass =btn btn-info>发送< / button>
< button type =buttonclass =btn btn-whitedata-dismiss =modal>关闭< / button>
< / div>
<?php}?>
< / div>
< / div>
< / div>
我无法从数据库中设置input type = file的值,
和if图像退出,然后出现更改按钮而不是选择图像。
当我选择新文件时,它正常工作,并且更改和删除按钮出现而不是选择文件。
请帮我解决。
注意:以上问题是连续的问题所以以下答案也是回答
您可以跳过< label class =idhere><?php echo $ id;?>< / label>
你需要的是一个ajax调用方法,用于从<?php $ id;?>
中获取数据库中的数据并以模态显示
$(document).ready(function(){
$('#modal-6')。on ('shown.bs.modal',function(e){
var id = $(e.relatedTarget).data('id');
$ .ajax({
type: 'post',
url:'file.php',//这里您将获取记录或图片
data:'id ='+ id,/ / pass id
success:function(data){
$('#fetched-data')。html(data); //显示从数据库获取的数据
}
} );
});
});
模态HTML将会是
< div class =modal fade validateid =modal-6>
< div class =modal-dialog>
< div class =modal-content>
< div id =fetched-data>< / div>
< / div>
< / div>
< / div>
和 file.php
($ _ POST ['id']){$ p
$ p $ <?php
//数据库连接
b $ b $ id = $ _POST ['id']; //转义字符串
//运行查询
//从数据库获取数据
// poplutae带值的HTML
?>
< div class =modal-header>
< button type =buttonclass =closedata-dismiss =modalaria-hidden =true>& times;< / button>
< h4 class =modal-title>编辑广告< / h4>
< / div>
<?php $ sel = $ d-> select('advertisements','ad_id = 12');
while($ result = mysqli_fetch_assoc($ sel)){
?>
< div class =modal-body>
< div class =row>
< div class =form-group col-md-6>
< label class =control-label>标题< / label>
< input class =form-controlvalue =<?php echo $ result ['title'];?> name =advertise_titledata-validate =requireddata-message-required =请输入标题placeholder =输入标题type =text>
< / div>
< div class =form-group col-md-6>
< label class =control-label> URL< / label>
< input class =form-controlname =advertise_urlvalue =<?php echo $ result ['url'];?> data-validate =requireddata-message-required =请输入网址占位符=输入网址type =text>
< / div>
< / div>
< div class =row>
< div class =col-md-12>
< div class =form-group no-margin>
< label for =descriptionclass =control-label>说明< / label>
< textarea class =form-control autogrowid =descriptionname =advertise_descplaceholder =描述关于查询的描述>
<?php echo trim($ result ['description']); ?>
< / textarea>
< / div>
< / div>
< / div>
< div class =row>
< div class =form-group col-md-6>
< label class =control-label>图片上传< / label>
< div>
< div class =fileinput fileinput-newdata-provide =fileinput>
< div class =fileinput-new thumbnailstyle =width:200px; height:150px;数据触发器= 的FileInput >
< img src =<?php echo $ result ['photo'];?>>
<! - < img src =images / thumbnail.jpegalt =...> - >
< / div>
< div class =fileinput-preview fileinput-exists thumbnailstyle =max-width:200px; max-height:150px>< / div>
< div>
< span class =btn btn-white btn-file>
< span class =fileinput-new>选择图片< / span>
< span class =fileinput-exists>更改< / span>
< input type =filename =advertise_photoaccept =image / *>
< / span>
< a href =#class =btn btn-orange fileinput-existsdata-dismiss =fileinput>删除< / a>
< / div>
< / div>
< / div>
< / div>
< / div>
< div class =row>
< div class =form-group col-md-6>
< label class =control-label> Active Flag< / label>
< input type =checkbox>
< / div>
< / div>
< / div>
< div class =modal-footer>
< button type =buttonclass =btn btn-info>发送< / button>
< button type =buttonclass =btn btn-whitedata-dismiss =modal>关闭< / button>
< / div>
<?php}}?>
如@devpro所示,您需要< form>< / form> ;
编辑/更新模态内填充的数据。
<div class="modal fade validate" id="modal-6">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit Advertisement</h4>
<label class="idhere"><?php echo $id;?></label>
</div>
<?php $sel = $d->select('advertisements','ad_id=12');
while($result = mysqli_fetch_assoc($sel)){
?>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Title</label>
<input class="form-control" value="<?php echo $result['title'];?>" name="advertise_title" data-validate="required" data-message-required="Please Enter Title" placeholder="Enter Title" type="text">
</div>
<div class="form-group col-md-6">
<label class="control-label">URL</label>
<input class="form-control" name="advertise_url" value="<?php echo $result['url'];?>" data-validate="required" data-message-required="Please Enter URL" placeholder="Enter URL" type="text">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="description" class="control-label">Description</label>
<textarea class="form-control autogrow" id="description" name="advertise_desc" placeholder="Describe Description Regarding Query">
<?php echo trim($result['description']); ?>
</textarea>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Image Upload</label>
<div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;" data-trigger="fileinput">
<img src="<?php echo $result['photo']; ?>">
<!-- <img src="images/thumbnail.jpeg" alt="..."> -->
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px"></div>
<div>
<span class="btn btn-white btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="advertise_photo" accept="image/*" >
</span>
<a href="#" class="btn btn-orange fileinput-exists" data-dismiss="fileinput">Remove</a>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Active Flag</label>
<input type="checkbox">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info">Send</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
<?php } ?>
</div>
</div>
</div>
I am unable to set the value of input type=file from database,and if the image is exits then change button appear instead of select image.when i am choosing new file it works properly,and change and remove button appear instead of select file.Please help me to solve it.
Note: Above question is continuous of this question so the following answer is also continuous of this answer
You can skip the <label class="idhere"><?php echo $id;?></label>
in JS what yo need is ajax call method to fetch data from database against <?php $id;?>
and display in modal
$(document).ready(function() {
$('#modal-6').on('shown.bs.modal', function(e) {
var id = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',
url : 'file.php', //Here you will fetch records or images
data : 'id='+ id, //Pass id
success : function(data){
$('#fetched-data').html(data);//Show fetched data from database
}
});
});
});
Modal HTML will be
<div class="modal fade validate" id="modal-6">
<div class="modal-dialog">
<div class="modal-content">
<div id="fetched-data"></div>
</div>
</div>
</div>
and file.php
will be
<?php
//database connection
if($_POST['id']) {
$id = $_POST['id']; //escape the string
//run query
//fetch data from database
//poplutae the HTML with values
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Edit Advertisement</h4>
</div>
<?php $sel = $d->select('advertisements','ad_id=12');
while($result = mysqli_fetch_assoc($sel)){
?>
<div class="modal-body">
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Title</label>
<input class="form-control" value="<?php echo $result['title'];?>" name="advertise_title" data-validate="required" data-message-required="Please Enter Title" placeholder="Enter Title" type="text">
</div>
<div class="form-group col-md-6">
<label class="control-label">URL</label>
<input class="form-control" name="advertise_url" value="<?php echo $result['url'];?>" data-validate="required" data-message-required="Please Enter URL" placeholder="Enter URL" type="text">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group no-margin">
<label for="description" class="control-label">Description</label>
<textarea class="form-control autogrow" id="description" name="advertise_desc" placeholder="Describe Description Regarding Query">
<?php echo trim($result['description']); ?>
</textarea>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Image Upload</label>
<div>
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;" data-trigger="fileinput">
<img src="<?php echo $result['photo']; ?>">
<!-- <img src="images/thumbnail.jpeg" alt="..."> -->
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px"></div>
<div>
<span class="btn btn-white btn-file">
<span class="fileinput-new">Select image</span>
<span class="fileinput-exists">Change</span>
<input type="file" name="advertise_photo" accept="image/*" >
</span>
<a href="#" class="btn btn-orange fileinput-exists" data-dismiss="fileinput">Remove</a>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label class="control-label">Active Flag</label>
<input type="checkbox">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info">Send</button>
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
<?php } } ?>
As suggested by @devpro you need <form></form>
to edit / update the populated data inside modal.
这篇关于如何在输入类型中设置值=数据库中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!