【发布时间】:2015-05-18 16:49:17
【问题描述】:
我的页面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
表格与我的眼睛基本相同,所以我不明白为什么一个发布正确的值而另一个没有发布任何内容。我错过了什么可笑的事情吗?
感谢您的建议
【问题讨论】:
-
使用“one”形式,而不是“deux”、“due”、“two”。您正在尝试在执行被调用的表单时访问其他表单之外的元素。
-
只有一个表单正在提交。您必须使用 JavaScript 来提交 n 表单或执行@Fred-ii- 所说的,这是更好的答案。
-
要是我能用那个兑现就好了,嗯 Sam? - @JayBlanchard
-
你可能会以我习惯的方式留住我@Fred-ii- ;-)
-
@JayBlanchard 我们再唱一遍那首歌好吗Sam? ^
标签: php html forms undefined-index