几乎相同的 HTML 表格,一个张贴正确的值,另一个不正确

Near identical HTML forms, one posts correct value, the other doesn't

我页面上的两个表格welcome.php如图:

<form action="welcomeforms.php" method="post" name="Food_Calories">
    <h4>.</h4>//spacer
    <input type="text" name="breakfast_calories" value="Calorie Amount" onFocus="this.value=''"><br>
    <input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;">
</form>


<form action="welcomeforms.php" method="post" name="Foods">
    <h4>Breakfast</h4>
    <input type="text" name="breakfast" value="Add new breakfast item" onFocus="this.value=''"><br>
    <input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;">
    </form>

这是 welcomeforms.php 上的代码:

if(isset($_POST['breakfast'])){$breakfastitem = $_POST['breakfast'];}
if(isset($_POST['breakfast_calories'])){$breakfastcals = $_POST['breakfast_calories'];}
echo $breakfastitem;
echo $breakfastcals;

表格在网页上正确显示,当我在早餐表格中输入值 'bread' 并在早餐表格中输入“100”时,网页上返回的是:

Undefined variable: breakfastitem in C:\wamp\www\welcomeforms.php on line 26
100

这些表格与我的眼睛基本相同,所以我不明白为什么一个 post 是正确的值而另一个 post 没有任何东西。我错过了什么荒谬的事情吗?

感谢任何建议

您正在使用两个单独的表单,一次只能提交一个。合二为一

也可以使用 placeholder = "Add new breakfast item" 而不是 value="Add new breakfast item" onFocus="this.value=''" - 它会做你打算在现代浏览器中获得的东西 - 请参阅支持:http://www.html5rocks.com/en/tutorials/forms/html5forms/#toc-other-form-attr

因为它一次只提交一个表单,所以它只从一个表单中获取值。