首页 > 解决方案 > 如何从 PHP 中的可点击图像进行 SQL 查询

问题描述

我正在建立一个新的网站,我想问你一个我想添加的功能。

我有一个用户可以删除产品的页面(来自 MySQLi 表的行)

到目前为止,我添加了一个在悬停时更改的图像

   <hmtl>
   ...
   <h6>
     <div class="Delete_product">
      //here user can press the delete image 
      // and i want to make an SQL Query like
      // "DELETE FROM `products` WHERE `products`.`product_id` = 8"
     </div>

    </html>

以及在悬停时更改删除图像的 CSS

css

.Delete_product                   {
   background-image:url('../code/Images/Buttons/DELETE.png');
   width: 330px; 
   height: 40px;
   background-position:center;
   background-repeat: no-repeat;   }

.Delete_product:hover              {
  background-image:url('../code/Images/Buttons/DELETE_active2.png');
  width: 330px; 
  height: 40px;
  background-position:center;
  background-repeat: no-repeat;    }

当用户按下 DELETE(图像)并在第二次再次询问他时如何执行 SQL DELETE 查询

(比如:你确定要删除这个产品吗)

标签: phphtmlcsssql

解决方案


您可以使用 AJAX。

$.post(
      'YOUR SCRIPT URL',
        {idToDelete : $(".Delete_product").data('idToDelete')},
        function(data){
          //do something if you wants
        }
    );

例如,在您的 php 脚本中,使用 POST 参数创建带有 ID 参数的 SQL 请求。

对于确认消息,您可以在单击元素时显示一个模式,当他按下接受按钮时,运行您的 ajax 请求。


推荐阅读