我的页面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;
表格在网页上正确显示,当我在早餐表格中输入值'面包',在早餐表格中输入'100'时,这是在网页上返回的内容:
Undefined variable: breakfastitem in C:\wamp\www\welcomeforms.php on line 26
100
表格与我的眼睛基本相同,所以我不明白为什么一个人发布了正确的价值而另一个没有发布任何内容。我错过了一些荒谬的东西吗?
感谢您的任何建议
答案 0 :(得分:0)
您使用的是两个单独的表单,一次只能提交一个表单。将它们合并为一个。
而不是value="Add new breakfast item" onFocus="this.value=''"
只使用placeholder = "Add new breakfast item"
- 它会执行您想要在现代浏览器中获得的内容 - 请参阅支持:http://www.html5rocks.com/en/tutorials/forms/html5forms/#toc-other-form-attr
答案 1 :(得分:0)
因为它一次只提交一个表单,所以它只从一个表单中获取值。