如何从代码

时间:2015-11-25 12:21:06

标签: javascript php

当我点击No按钮时,我想从数据库中删除图像..

由于单行中有多个图像,因此该代码对此有用..

单一模型弹出窗口在我点击其缩略图时显示图像,在弹出模型上显示是和否按钮,

开启“是”按钮缩略图应该是原样,数据库中没有变化。 但是在“否”按钮上它应该从弹出模型中打开的数据库中删除该特定图像。

我是否需要将JavaScript变量传递给php代码?

$(function popup() {
		$('.pop').on('click', function popup() {
			$('.imagepreview').attr('src', $(this).find('img').attr('src'));
			$('#imagemodal').modal('show');   
		});		
});
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
  
  
<a href="#" class="pop">
    <img src="http://patyshibuya.com.br/wp-content/uploads/2014/04/04.jpg" style="width: 400px; height: 264px;" class="img-responsive">
</a>
    
<a href="#" class="pop">
    <img src="http://upload.wikimedia.org/wikipedia/commons/2/22/Turkish_Van_Cat.jpg" style="width: 400px; height: 264px;">
</a>
<!-- Image Popup to large image  -->							
															
<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" data-dismiss="modal">
    <div class="modal-content"  >              
      <div class="modal-body"><form action="#" method="POST">
      	<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <img src="" class="imagepreview" style="width: 100%;" >
      </div> 
      <div class="modal-footer">
      <center>
     	  <div class="col-xs-12">Do you want to verify this? &nbsp;
               <button type="button" class="btn btn-success" name="yes">Yes</button> &nbsp; 
               <button type="button" class="btn btn-danger" name="no">No</button>
          </div>
        </form>
          </center>
      </div>
    </div>
  </div>
</div>

下面是我的PHP代码。

if(isset($_POST['no'])) {
                $imagename = $_POST['imagename'];

 $update= "UPDATE usertable SET profile_image= NULL WHERE id='$id'";

                if(mysql_query($update)) {
                    echo "Successful!";
                    echo $imagename;
                } else {
                    echo mysql_error();
                }
            }

1 个答案:

答案 0 :(得分:1)

在你的html中进行以下更改:

<img src="" class="imagepreview" style="width: 100%;" id="deleteimage" >

在您的JS文件中添加以下代码:

delete = $("#deleteimage").attr('src');

然后通过这个&#34;删除&#34;使用ajax为您的服务器赋值。

your field in database "profile_image" what it actually contains. single image or multiple ?