PHP会产生令人困惑的输出

时间:2013-10-23 08:46:09

标签: php html forms

我正在尝试构建一个每个条目都有一个删除按钮的表,但输出让我感到困惑。代码如下:

                    if ($players != null) {

                        echo('<table class="playerTable">');
                        echo('<thead>');
                        echo('<tr>');
                        echo('<th> Last Name </th>');
                        echo('<th> First Name </th>');
                        echo('<th></th>');
                        echo('<th></th>');
                        echo('</tr></thead><tbody>');

                        for ($i=0; $i<count($players); $i++) {
                           printf('<form action="player.php" method="post" onSubmit="return submitCheck(\'%s\', \'%s\')">', $players[$i]->name, $players[$i]->surname);
                           echo("<tr>");
                           printf("<td> %s </td><td> %s </td>", $players[$i]->surname, $players[$i]->name);
                           echo('<td><input type="hidden" name="delete" value="'. $players[$i]->id .'"></td>');
                           echo('<td><input type="submit" value="Delete"></td>');
                           echo("</tr>");
                           echo('</form'); 


                        }
                        echo('</tbody></table>');
                    }

由于某种原因,我没有得到,产生的输出如下:

<tbody>
<form action="player.php" method="post" onsubmit="return submitCheck('someName', 'someName')"></form>
<tr>
    <td> someName </td>
    <td> someName </td>
    <td><input type="hidden" name="delete" value="1"></td>
    <td><input type="submit" value="Delete">
    </td>
</tr>

当然导致提交检查不会被执行 - 我在这里缺少什么?

2 个答案:

答案 0 :(得分:0)

首先,您不应在<form>中拥有<table>标记。反过来说吧。此外,在您的开始<form>标记中,操作属性中缺少=符号。 <form>的结束标记也应该在<table>之外。

答案 1 :(得分:0)

=中没有action"player.php" 试试action="player.php"