回声 - > html =混乱

时间:2015-03-27 09:00:04

标签: php html sql database


我尝试在HTML表格中输出PHP中的数据库表。当我在HTML中查看输出时,它完全搞砸了。在我看来一切都是正确的。也许有人看到了这个错误。

我的PHP文件:

<table id="table_id" class="display table table-hover table-responsive table-striped">
<thead>
<tr>
<th class="col-md-3">Gespeichert am</th>
<th class="col-md-5">Text</th>
<th class="col-md-3">Kategorie</th>
<th class="col-md-1"><span class='glyphicon glyphicon-remove' aria-hidden='true'></span></th>
</tr>
</thead>
<tbody>
<?php
while($row=mysql_fetch_object($ergebnis))
{
echo "<tr>";
echo "<td>".date("H:i - d.m.y",strtotime($row->Zeit) + 60*60)."</td>";
echo "<td><a href='".$row->url."' target='_blank'>".$row->text."</a></td>";
echo "<td>".$row->kategorie."</td>";
echo "<form action='delete.php' method='post'>";
echo "<td>";
echo "<input type='hidden' name='delete_id' value='".$row->id."'</td>";
echo "<button onClick='submit();' style='border:none; background-color:transparent; padding:0px;' type='submit' value='Delete'><span class='glyphicon glyphicon-remove delete' aria-hidden='true'></span></button>";
echo "</td>";
echo "</form>";
echo "</tr>";
}
?>
</tbody>
</table>



HTML中的输出如下所示:

<table id="table_id" class="display table table-hover table-responsive table-striped">
<thead>
<tr>
<th class="col-md-3">Gespeichert am</th>
<th class="col-md-5">Text</th>
<th class="col-md-3">Kategorie</th>
<th class="col-md-1"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></th>
</tr>
</thead>
<tbody>
<tr>
<td>15:46 - 26.03.15</td>
<td><a href="http://Www.google.de" target="_blank">Google link</a></td>
<td>Web</td>
<form action="delete.php" method="post"></form>
<td><input type="hidden" name="delete_id" value="37" <="" td="">
<button onclick="submit();" style="border:none; background-color:transparent; padding:0px;" type="submit" value="Delete">
<span class="glyphicon glyphicon-remove delete" aria-hidden="true"></span>
</button>
</td>
</tr>
</tbody>
</table>

1 个答案:

答案 0 :(得分:0)

<form>放在表格的单元格内(<td>内),或将其环绕整个表格。

问题在于<tr>仅允许<th><td>个节点内部存在,这就是为什么<form>搞砸了。

此外,正如评论中已经提到的那样,以下行有错误导致html损坏:

echo "<input type='hidden' name='delete_id' value='".$row->id."'</td>";

应该是:

echo "<input type='hidden' name='delete_id' value='".$row->id."'></td>";