gpt4 book ai didi

javascript - PHP使用复选框从数据表中删除多行

转载 作者:行者123 更新时间:2023-11-29 18:20:50 25 4
gpt4 key购买 nike

我正在尝试使用 mysql 从 php 数据表中删除多个选定的行。但是收到以下 print_r($_POST); 返回 2 行数据:

Array ( [user_payment_request_length] => 10 [checked_id] => Array ( [0] => [1] => ) [select_all] => [bulk_delete_submit] => )

没有数据传递以使 mysql 过程成功。特别是 $pr_id,它是一个整数。当我尝试按以下方式打印时:

foreach ($idArrr as $pr_id) {
echo $pr_id;
}

显示数组到字符串转换错误。这是我的完整代码:

   $(document).ready(function () {
$('input').val('');
});
$(document).ready(function () {
$('#user_payment_request').DataTable();
});

function deleteConfirm() {
var result = confirm("Are you sure to delete?");
if (result) {
return true;
} else {
return false;
}
}

$(document).ready(function () {
$('#select_all').on('click', function () {
if (this.checked) {
$('.checkbox').each(function () {
this.checked = true;
});
} else {
$('.checkbox').each(function () {
this.checked = false;
});
}
});

$('.checkbox').on('click', function () {
if ($('.checkbox:checked').length == $('.checkbox').length) {
$('#select_all').prop('checked', true);
} else {
$('#select_all').prop('checked', false);
}
});
});
$stmt_payment = $mysqli->prepare('SELECT pr_id,pr_rqtime,pr_amount,pr_processor,pr_status,pr_date FROM payment WHERE user_id = ? ');
$stmt_payment->bind_param('i', $user_id);
$stmt_payment->execute(); // Execute the prepared query.
$stmt_payment->store_result();
$stmt_payment->bind_result($pr_id, $pr_rqtime, $pr_amount, $pr_processor, $pr_status, $pr_date);
?>
<form name="payment_table" method="post" onsubmit="return deleteConfirm();">
<table id="user_payment_request" class="table table-responsive table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th>Payment ID </th>
<th>Payment Request Time</th>
<th>Amount</th>
<th>Processor</th>
<th>Status</th>
<th>Payment Date</th>
<th>Select</th>
</tr>
</thead>

<?php
while ($stmt_payment->fetch()) {
?>
<tbody>
<tr>
<td> <?php echo $pr_id; ?> </td>
<td> <?php echo $pr_rqtime; ?> </td>
<td> <?php echo $pr_amount; ?> </td>
<td> <?php echo $pr_processor; ?></td>
<td><?php echo $pr_status; ?> </td>
<td><?php echo $pr_date; ?></td>
<td> <input type="checkbox" name="checked_id[]" class="checkbox" value="<?php echo $pr_id; ?>"/></td>
</tr>
<?php
}
?>
</tbody>
</table>
<strong>Select All <input type="checkbox" name="select_all" id="select_all" value=""/> </strong>
<button type="submit" class="btn btn-danger" name="bulk_delete_submit">Delete</button>
</form>
<?php
//----Delete record part
print_r($_POST);
if (isset($_POST['bulk_delete_submit'])) {
$idArrr[] = $_POST['checked_id'];
foreach ($idArrr as $pr_id) {
$stmt_delete_payment = $mysqli->prepare("CALL user_delete_payment(?,?,?,?,?)");
$stmt_delete_payment->bind_param('iisds', $pr_id, $user_id, $pr_rqtime, $pr_amount, $pr_processor);
if (!$stmt_delete_payment->execute()) {
echo '<script>swal("Error!", "Database error deleting payout request, please try again", "error");</script>';
echo '<script>setTimeout(function(){location.href = "withdraw.php";},2000); </script>';
}
}
$stmt_delete_payment->close();
echo '<script>location.href = "withdraw.php";</script>';
}
// end of delete records
$stmt_payment->close();
?>

最佳答案

我明白了,我有额外的 JavaScript 代码:

                        $(document).ready(function () {
$('input').val('');
});

正在删除输入值。这就是代码不起作用的原因。我有额外的代码,以便在用户按后退按钮时删除表单的值

关于javascript - PHP使用复选框从数据表中删除多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46598190/

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