我在while循环中有一些表行,这些行都是数据库中的所有数据,每行都有一个提交按钮。我想将特定数据发布到另一个页面,例如,如果我按Submit_3,那么我想将第3行的所有数据发布到otherpage.php,但是按照我尝试的方式,它总是使用最后一行。
例如,我有25行,然后我提交按钮3,它将发布第25行中的所有信息。
print '<form method="POST" action="edit.php" name="action">';
//print '<input type="hidden" value="'.$imId.'" name="imId">';
print '<div class="tbl-content">';
print '<table cellpadding="0" cellspacing="0" border="0">';
print '<tbody>';
$querySelect = "select hersteller, name, kaufDatum, category, ablaufDatum, imID, details from inventoryManager ";
$querySelect .= $orderBy;
error_log( "SQL2:" . $querySelect . "<br>", 3, "C:/Control/log/debug/dp.html" );
$resultSelect = db_query( [ $querySelect ] );
while ( ( $row = mysql_fetch_array( $resultSelect ) ) ) {
$manufacturer = $row[ hersteller ];
$name = $row[ name ];
$buyDate = $row[ kaufDatum ];
$selectCategory = $row[ category ];
$expireDate = $row[ ablaufDatum ];
$imId = $row[ imID ];
$details = $row[ details ];
print '<tr>';
print "<td>$manufacturer</td>";
print "<td>$name</td>";
print "<td>$buyDate</td>";
print "<td>$selectCategory</td>";
print "<td>$expireDate</td>";
//error_log("imIdCheck#1:".$imId."<br>",3,"C:/Control/log/debug/dp.html");
print '<td><input type="submit" name="edit_' . $imId . '" value="Bearbeiten" class="button2 button3"></td>';
print '</tr>';
}
print '</tbody>';
print '</table>';
print '</div>';
print '</form>';
在另一页上,我选择了所有带有$ imId的数据,但是每次我按下一个提交按钮时,即使它的commit_1出现了最后一步。 我必须包括哪些内容才能提交所选行的数据?
编辑:在实施建议具有按钮之后的一些HTML代码:
<form method="POST" action="edit.php" name="action">
<div class="tbl-content">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td>test</td>
<td>TestName</td>
<td>2019-03-23</td>
<td></td>
<td>2019-03-22</td>
<input type="hidden" value="2" name="imId">
<td>
<button type="submit" name="id" value="2" class="button2 button3">Bearbeiten</button>
</td>
</tr>
<tr>
<td>TestHersteller</td>
<td>TestName</td>
<td>2019-03-31</td>
<td></td>
<td>2019-03-31</td>
<input type="hidden" value="3" name="imId">
<td>
<button type="submit" name="id" value="3" class="button2 button3">Bearbeiten</button>
答案 0 :(得分:2)
如果您有一个表单,那么我建议您删除已隐藏的字段,以使命名提交按钮发送ID起作用。确保您以在PHP中读写iID的方式进行拼写,然后单击每个按钮将向服务器发送ID为点击按钮值的ID
<button type="submit" name="imID" value="'.$imId.'" class="button2 button3">Bearbeiten/button>
赞:
<form method="POST" action="edit.php" name="action">
<div class="tbl-content">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td>test</td>
<td>TestName</td>
<td>2019-03-23</td>
<td></td>
<td>2019-03-22</td>
<td>
<button type="submit" name="imID" value="2" class="button2 button3">Bearbeiten</button></td>
</tr>
<tr>
<td>TestHersteller</td>
<td>TestName</td>
<td>2019-03-31</td>
<td></td>
<td>2019-03-31</td>
<td>
<button type="submit" name="imID" value="3" class="button2 button3">Bearbeiten</button>
....