<a href="" data-toggle="modal" class="update_pic" data_id = "$id" data-target="#update-modal"><img height="100px" width="100px" src="data:image/jpeg;base64,'.base64_encode( $row['pestImage'] ).'"/><a/></td>';
echo"<td>$imagedesc $id</td>";
echo"<td>$pestname</td>";
echo"<td>$pesticide</td>";
echo"<td>
<form action='editpest.php?id=$id' method='POST'>
<button data-toggle='modal' class='btn btn-primary btn-sm btn-block' data-target='#update-modal'>Edit</button>
<br/>
<form action='../php/deletepest.php?id=$id' method='POST'>
<button class='btn btn-danger btn-sm btn-block'>Delete</button>
</form>
</td>";
echo'</tr>';
<div id="update-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h1 class="modal-title">Update Picture Pest</h1>
</div>
<div class="modal-body">
<?php echo" <form action='../php/updateImage2.php?id=$id' method='POST'>;"?>
<div style="position:relative;">
<div class="input-group image-preview">
<input type="text" class="form-control image-preview-filename" disabled="disabled"> <!-- don't give a name === doesn't send on POST/GET -->
<span class="input-group-btn">
<!-- image-preview-clear button -->
<button type="button" class="btn btn-default image-preview-clear" style="display:none;">
<span class="glyphicon glyphicon-remove"></span> Clear
</button>
<!-- image-preview-input -->
<div class="btn btn-default image-preview-input">
<span class="glyphicon glyphicon-folder-open"></span>
<span class="image-preview-input-title">Browse</span>
<input type="file" accept="image/png, image/jpeg, image/gif" name="input-file-preview"/> <!-- rename it -->
</div>
</span>
</div>
<br/>
<br/>
<div class="form-group">
<div class="col-lg-7 col-lg-offset-7.5">
<button type="submit" class="btn btn-primary btn-lg">Update Picture</button>
</div>
</div>
</form>
您好我想将从数据库中检索到的$ id的值传递给模态,因此我可以在更新图像时将其用作Where子句。
这是我的第一个问题,希望有人会回答
答案 0 :(得分:0)
<a href="" data-toggle="modal" class="update_pic" data_id = "$id" data-target="#update-modal">
<img height="100px" width="100px" src="data:image/jpeg;base64,'.base64_encode( $row['pestImage'] ).'"/>
<a/>
</td>
<td><?php echo $imagedesc.''.$id;?></td>
<td><?php echo $pestname;?></td>
<td><?php echo $pesticide;?></td>
<td>
<a class='editClass' href="#form_modal" data-toggle="modal" data-id="<?echo $id;?>">
Edit
</a>
<form action='../php/deletepest.php?id=$id' method='POST'>
<button class='btn btn-danger btn-sm btn-block'>Delete</button>
</form>
</td>
</tr>
<强> JS 强>
<script>
$('.editClass').click(function(){
var id=$(this).attr('data-id');
$.ajax({url:"editpest.php?id="+id,cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
页脚(将此代码放在页脚或<table></table>
下方
<div class="modal fade" id="form_modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
editpest.php
<?php
$id = $_GET['id'];
// Now, write your query here
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Update</h4>
</div>
<div class="modal-body">
.
.
<?php echo "Id: ".$id;?>
.
.
// Write code here to update
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>