2016-01-27 77 views
-5
<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">&times;</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子句。從窗體到模態在php中傳遞值

這是我的第一個問題,希望有人會回答

+0

再試一次吧。 – Flosculus

+2

請考慮修復代碼格式。 –

+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">&times;</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> 
+0

謝謝我從你的代碼中得到了很多想法。先生, –

+0

如果你認爲這個答案對你有幫助。請勾選此答案作爲正確答案。因爲它可以幫助其他用戶輕鬆找到它。謝謝@JersonBabieraGevera。 *很高興幫助*':)' –

相關問題