我有些麻烦让一些HTML / PHP工作。我有一个包含3个基本表区域的HTML文件。在一个区域中,我有一个输入字段和一个与SQL数据库通信的按钮,用于删除HTML框中提供的条目。在第二个表格行中,我有一个表单,用于将新项目添加到数据库中。
然而,当我按下第二个表区域中的按钮时,它会运行第一个PHP函数。我错过了什么吗?
<table width="651" height="231" border="1">
<tr>
<td width="1163" height="23"> </td>
</tr>
<tr>
<td height="96">
<table>
<form method=post action="removeRecord.php">
<input type="text" name="boatNumber" font color="white"> Enter a boat to remove<br>
<input type=submit value="Remove boat">
</table>
</td>
</tr>
<tr>
<td height="102">
<h1>Register a new boat.</h1>
<table>
<form method=post action="addRecord.php">
<input type="text" name="boatNumberNew" font color="white"> Enter the boats number.<br>
<input type="text" name="boatType" font color="white"> Enter the type of boat.<br>
<input type="text" name="decks" font color="white"> :Number of Decks<br>
<input type="text" name="cabins" font color="white"> :Number of cabins<br>
<input type="text" name="location" font color="white"> Location.<br>
<input type="text" name="rent" font color="white"> Rent.<br>
<input type="text" name="staffNumber" font color="white"> Enter assigned staff member.<br>
<input type="text" name="branchNumber" font color="white"> Enter assigned branch.<br>
<input type="text" name="ownerNumber" font color="white"> Enter owner number.<br>
<input type=submit value="Add boat">
</table>
</td>
</tr>
</table>
答案 0 :(得分:2)
您错过了两个表单的结束</form>
标记。
另外,引用type=submit
和method=post
这是重写:
<table width="651" height="231" border="1">
<tr>
<td width="1163" height="23"> </td>
</tr>
<tr>
<td height="96">
<table>
<form method="post" action="removeRecord.php">
<input type="text" name="boatNumber" font color="white"> Enter a boat to remove<br>
<input type="submit" value="Remove boat">
</form>
</table>
</td>
</tr>
<tr>
<td height="102">
<h1>Register a new boat.</h1>
<table>
<form method="post" action="addRecord.php">
<input type="text" name="boatNumberNew" font color="white"> Enter the boats number.<br>
<input type="text" name="boatType" font color="white"> Enter the type of boat.<br>
<input type="text" name="decks" font color="white"> :Number of Decks<br>
<input type="text" name="cabins" font color="white"> :Number of cabins<br>
<input type="text" name="location" font color="white"> Location.<br>
<input type="text" name="rent" font color="white"> Rent.<br>
<input type="text" name="staffNumber" font color="white"> Enter assigned staff member.<br>
<input type="text" name="branchNumber" font color="white"> Enter assigned branch.<br>
<input type="text" name="ownerNumber" font color="white"> Enter owner number.<br>
<input type="submit" value="Add boat">
</form>
</table>
</td>
</tr>
</table>
应用Marc B的建议进行另一次改写:
<table width="651" height="231" border="1">
<tr>
<td width="1163" height="23"> </td>
</tr>
<tr>
<td height="96">
<form method="post" action="removeRecord.php">
<table>
<input type="text" name="boatNumber" font color="white"> Enter a boat to remove<br>
<input type="submit" value="Remove boat">
</table>
</form>
</td>
</tr>
<tr>
<td height="102">
<h1>Register a new boat.</h1>
<form method="post" action="addRecord.php">
<table>
<input type="text" name="boatNumberNew" font color="white"> Enter the boats number.<br>
<input type="text" name="boatType" font color="white"> Enter the type of boat.<br>
<input type="text" name="decks" font color="white"> :Number of Decks<br>
<input type="text" name="cabins" font color="white"> :Number of cabins<br>
<input type="text" name="location" font color="white"> Location.<br>
<input type="text" name="rent" font color="white"> Rent.<br>
<input type="text" name="staffNumber" font color="white"> Enter assigned staff member.<br>
<input type="text" name="branchNumber" font color="white"> Enter assigned branch.<br>
<input type="text" name="ownerNumber" font color="white"> Enter owner number.<br>
<input type="submit" value="Add boat">
</table>
</form>
</td>
</tr>
</table>
答案 1 :(得分:2)
您的HTML从根本上被打破了:
<table>
<form>...</form>
</table>
无效。 <table>
只能有与表相关的子节点(tr,td,thead,tbody等)。表格应该在表格之外:
<form>
<table> ... </table>
</form>
另外,你永远不会关闭你打开的第一个表格,这意味着:
<form action="foo.php">
...
<form action="bar.php">
<input type="submit">
</form>
将提交给foo.php
,因为您无法将表单嵌套在彼此中。
答案 2 :(得分:1)
您需要添加
<input type="hidden" name="action" value="youraction"/>
告诉php执行哪种形式的php验证
第二,您缺少表单</form>
答案 3 :(得分:0)
使用</form>
关闭表单
</form>
<table width="651" height="231" border="1">
<tr>
<td width="1163" height="23"> </td>
</tr>
<tr>
<td height="96">
<table>
<form method=post action="removeRecord.php">
<input type="text" name="boatNumber" font color="white"> Enter a boat to remove<br>
<input type=submit value="Remove boat">
</form>
</table>
</td>
</tr>
<tr>
<td height="102">
<h1>Register a new boat.</h1>
<table>
<form method=post action="addRecord.php">
<input type="text" name="boatNumberNew" font color="white"> Enter the boats number.<br>
<input type="text" name="boatType" font color="white"> Enter the type of boat.<br>
<input type="text" name="decks" font color="white"> :Number of Decks<br>
<input type="text" name="cabins" font color="white"> :Number of cabins<br>
<input type="text" name="location" font color="white"> Location.<br>
<input type="text" name="rent" font color="white"> Rent.<br>
<input type="text" name="staffNumber" font color="white"> Enter assigned staff member.<br>
<input type="text" name="branchNumber" font color="white"> Enter assigned branch.<br>
<input type="text" name="ownerNumber" font color="white"> Enter owner number.<br>
<input type=submit value="Add boat">
</form>
</table>
</td>
</tr>
</table>