我有一个问题,我的while循环中的代码在第一次运行中没有form标记,但是在随后的运行中它在那里。
<?php
$num = 1;
while ($row = mysqli_fetch_object($daten)) {
echo "<tr>";
echo "<th>". $num. "</th>";
echo "<td>". htmlspecialchars($row->vname)." ".htmlspecialchars($row->nname)."</td>";
echo "<td>". htmlspecialchars($row->mail)."</td>";
echo "<td>"; ?>
<form action='/resources/user_loeschen.php' method='post'>
<input type='hidden' name='mail' value='<?php echo htmlspecialchars($row->mail); ?>'>
<a onclick='this.parentElement.submit();'><img class='delete' src='resources/img/glyphicons-17-bin.png' height='25px'></a>
</form>
</td>
</tr>
<?php
$num++;
} ?>
所以这是while循环中的代码。该表格应始终存在。我能想象的唯一问题是while循环本身也是一种形式。但是,仅循环的第一个运行会失败,而随后的运行却可以正常运行的事实很好地证明了它可以正常工作。
结果html:
<tr>
<th>1</th>
<td>First Test</td>
<td>test.first@test.com</td>
<td>
<input type='hidden' name='mail' value='test.first@test.com'>
<a onclick='this.parentElement.submit();'><img class='delete' src='resources/img/glyphicons-17-bin.png' height='25px'></a>
</td>
</tr>
<tr>
<th>2</th>
<td>Test User</td>
<td>test.user@test.com</td>
<td>
<form action='/resources/user_loeschen.php' method='post'>
<input type='hidden' name='mail' value='test.user@test.com'>
<a onclick='this.parentElement.submit();'><img class='delete' src='resources/img/glyphicons-17-bin.png' height='25px'></a>
</form>
</td>
</tr>
谢谢。