gpt4 book ai didi

php - 将表格数据发送到弹出删除

转载 作者:行者123 更新时间:2023-11-28 09:34:39 25 4
gpt4 key购买 nike

我正在尝试删除我的 html 表中的一个字段。当我单击删除按钮时,我将用户重定向到一个弹出窗口,询问他们是否确定要删除表中的那一行。一旦他们单击是,它会将他们带到一个 delete.php 文件,该文件将其从我们的数据库中删除。我不确定如何将此值发送到我们的 delete.php 文件。

  <!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>User Name</th>
<th>Distinct Items</th>
<th>Total Occurrences</th>
<th>Last Occurrence</th>
<th>Environment</th>
<th>Control</th>
</tr>
</thead>
<tbody>


<?php

include ("config.php");

$sql = "SELECT * FROM newTable";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'. $row['account_id'] . '</td>';
echo '<td>'. $row['user'] . '</td>';
echo '<td>'. $row['pass'] . '</td>';
echo '<td>'. $row['privs'] . '</td>';
echo '<td>'. $row['privValue'] . '</td>';
echo '<td>';
echo '<a href="#Modal_modify" class="btn btn-primary btn-xs" data-toggle="modal"><i class="fa fa-pencil"></i></a>';
echo '<a href="#Modal_delete" class="btn btn-danger btn-xs" data-toggle="modal"><i class="fa fa-trash-o "></i></a>';
echo '</td>';
echo '</tr>';
}
?>





<!-- Modal_delete HTML -->
<div id="Modal_delete" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">Delete User</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this user?</p>
</div>

<form action="delete_user.php" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>"/>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-danger">Delete</button>
</div>
</form>

</div>
</div>
</div>

问题是创建删除按钮 我引用了一个 html 子例程来创建单击后的弹出窗口。如何将表格数据发送到我的 delete.php 文件?

<?php
include ("test.php");

$tbl_name="newTable"; // Table name

$id = $_POST['id'];

echo $_POST['id'];

echo "$id";
// To protect MySQL injection (more detail about MySQL injection)

$sql="DELETE FROM tbl_name WHERE account_id='$id';";
mysql_query(sql);

header("Location: adminUser.php");




?>

最佳答案

你反对使用 jquery 吗? (抱歉,我会事先在评论中问这个,但是,tsk,没有足够的声誉,所以这是我的全部答案:)以下将非常简单:

$('.btn-danger').click(function(event) {
$('#Modal_delete').css('display', 'initial'); // swap this for however you're showing your delete confirmation popup. I just had it for testing.
var rowToDeleteID = $(event.currentTarget).parents('tr').attr('id'); // you'd need to add a unique id to each table row for this to work.
$('input[type="hidden"]').val(rowToDeleteID);
});

当然,如果您将唯一标识符添加到删除按钮(带有 fa-trash-o 图标的 a 标签)和隐藏的输入字段。

关于php - 将表格数据发送到弹出删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25588280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com