Im having some troubling getting some HTML/PHP to work. Ive got a HTML file that contains 3 basic table areas. In one area I have a input field and a button that communicates with a SQL database to remove the entry supplied from the HTML box. In the second table line I have a form to add a new item into the database.
However when I press the button in the second table area it runs the first PHP function. Am I missing anything?
<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>
You're missing closing </form>
tags for both your forms.
Plus, quotes around type=submit
and method=post
Here's a rewrite:
<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>
Another rewrite applying Marc B's recommendations:
<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>
Use the </form>
to close the forms
</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>
You need to add
<input type="hidden" name="action" value="youraction"/>
to tell php which form php validation to execute
second you are missing end tag of form </form>
Your HTML is fundamentally broken:
<table>
<form>...</form>
</table>
is invalid. a <table>
can only have table-related child nodes (tr, td, thead, tbody, etc...). Forms should go OUTSIDE the table:
<form>
<table> ... </table>
</form>
Plus, you never close the first form you open, which means that:
<form action="foo.php">
...
<form action="bar.php">
<input type="submit">
</form>
Will submit to foo.php
, because you cannot nest forms inside each other.