【发布时间】:2022-06-12 00:14:45
【问题描述】:
我成功创建了一个脚本,如果选中该行上的复选框(该复选框包含 rowID),该脚本将删除该表的行。用于删除这些行的复选框和按钮位于相同的表单标签内。现在我想创建另一个按钮,它使用复选框的值来执行不同的更新语句,但复选框的值没有出现在这个单独页面的 $_POST 中。
有谁知道如何使复选框值在其内部的表单操作之外可访问?这是我为删除有效的简化代码:
在 PickTicket.php 上调用下面的函数来显示一个表格。
Function DisplayPickTicket() {
$conn = getDBConnection();
$sql = "SELECT * FROM dbo.BK_NotesRecord WHERE StatusID = 1 ";
$stmt = sqlsrv_query( $conn, $sql );
if ( $stmt === false ) {
die( print_r( sqlsrv_errors(), true) );
}
echo '<form action="updatepickstatus.php" method="post">';
// Delete Checkbox header.
echo '<th class="table-header" style="width:5px;">';
echo 'Delete';
echo '</th>';
// Inventory number header.
echo '<th class="table-header" style="width:90px;">';
echo 'Inventory #';
echo '</th>';
//InventoryID Header
echo '<th class="table-header" style="width:40px;">';
echo 'InventoryID';
echo '</th>';
if (sqlsrv_has_rows($stmt)) {
while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) {
echo '<tr>';
//Delete checkbox
echo '<td class="cell"><div class="cell">';
echo '<input type = "checkbox" name="chkbox[]" value= "' .$row['InventoryID'].
'">';
echo '</td>';
// Inventory#
echo '<td class="cell"><div class="cell">';
echo $row["InventoryNumber"];
echo '</td>';
// InventoryID.
echo '<td class="cell"><div class="cell">';
echo $row["InventoryID"];
echo '</td>';
}
}
echo "<tr>";
echo "<td>";
echo "<input type='submit' name='submit' Value='Remove'>";
echo '</form>';
echo "</td>";
echo "</tr>";
这是updatepickstatus.php:
<?php
$serverName = "(local)";
$connectionOptions = array("Database"=>"Powerlink");
$conn = sqlsrv_connect( $serverName, $connectionOptions);
if( $conn === false ) {
echo "Connection failed!<br>";
die( print_r( sqlsrv_errors(), true));
}
if (isset($_POST['chkbox'])) {
foreach($_POST['chkbox'] as $Update) {
$sql = "UPDATE BK_NotesRecord set StatusID = '2' WHERE InventoryID LIKE '".$Update."'";
$stmt = sqlsrv_query( $conn, $sql );
//echo '$ids';
}
}
print_r($_POST);
?>
^^我想完成同样的基本任务,但在 updatepickstatus.php 之外。当应用类似的逻辑来检查 不同 上选定复选框的值时,我得到一个空数组。有什么想法吗?
【问题讨论】:
标签: javascript php html