php - 如何从 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 查询
(比如:你确定要删除这个产品吗)
解决方案
您可以使用 AJAX。
$.post(
'YOUR SCRIPT URL',
{idToDelete : $(".Delete_product").data('idToDelete')},
function(data){
//do something if you wants
}
);
例如,在您的 php 脚本中,使用 POST 参数创建带有 ID 参数的 SQL 请求。
对于确认消息,您可以在单击元素时显示一个模式,当他按下接受按钮时,运行您的 ajax 请求。
推荐阅读
- javascript - 使用邮递员上传图像文件,但我的代码不起作用。有什么需要做的改变吗?
- java - 如何获得选中的复选框jstl
- jenkins - 由于“job_template”更改,种子作业每分钟无限重复构建
- javascript - 我有 ReferenceError 我的对象未定义
- node.js - 单元测试快速路由器
- android - 如何更改我的 android 项目中的搜索图标颜色?
- apache - 代理反向 - Apache
- ios - 数据不解析我想将数据解析成字典然后解析成数组然后迭代它
- typescript - 使用带有打字稿的 vue-cli-service
- nestjs - 未找到连接“默认”-TypeORM、NestJS 和外部 NPM 包