0
我試圖刪除從PHP數據表的多個選定的行與mysql.But接收以下print_r($_POST);
返回2行的數據:PHP刪除的倍數行從數據表與複選框
陣列([user_payment_request_length] => 10 [checked_id] =>數組( [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();
?>
聽起來像「$ pr_id」是一個數組 - 也許如果你嘗試print_r($ pr_id),那麼它將開始變得更有意義。 –
@PaulColdrey我試着用print_r($ pr_id),但不幸的是$ pr_id沒有傳遞任何值。這是我得到的輸出'Array([0] => [1] =>)' – mimi