![](/img/trans.png)
[英]Undefined index: email in C:\wamp\www\emailvalidate.php on line 4
[英]Undefined index: type in C:\wamp\www\submit.php on line 4
嗨,我有未定义索引的问题。 在 google chrome 和 mozilla 中,它显示了通知,但在资源管理器中一切正常,但它不起作用。 我的 PHP 版本是 5.3.5。
代码:HTML 文件
<div id="stylized" class="myform">
<form action="submit.php" method="post" id="Form">
<ol>
<label for="number">number:</label>
<input name="number" class="text" type="text" size="28"/>
<div id="butt">
<input type="hidden" style="width: 150px; border: 1px solid gray" value="addd" name="type" />
<input type="submit" class="formbutton" value="add" />
</div>
<div id="error"> </div>
</ol>
<div class="spacer"></div>
</form>
</div>
提交文件 submit.php
switch ($_POST['type']){
case "register":
register();
break;
case "login":
login();
break;
default:
die(msg(0, "error"));
}
错误:
Notice: Undefined index: type in C:\wamp\www\submit.php on line 4
我已经尝试过:
if (isset($_POST['type']))
$type = $_POST['type'];
以及在其他主题上发现的许多其他建议,但在这种情况下似乎没有帮助
您没有名为“type”的输入? 尝试将 $_POST['type'] 更改为 $_POST['number'],如果这是您需要的数据。
我猜你最终会通过提交上述表单之外的其他途径进入submit.php
。
试试这个:
switch (isset($_POST['type']) ? $_POST['type'] : NULL) {
或者替代的,通常要避免但可能在这里的方法:
switch (@$_POST['type']) {
$_REQUEST['type'] = ( isset($_REQUEST['type']) ? $_REQUEST['type'] : '' )
检查变量是否已设置 - 如果没有,请将其设置为空白,尽管我会检查您的表单以了解为什么未设置帖子字段
你可以用这一行跳过这个错误
`ini_set("display_errors", "off");`
当您使用会话或数组时会返回此错误,但尚未解释索引,要解决此问题,您需要添加空值或如果尚未使用此索引,则需要添加任何您喜欢的值。
您的
<input type="hidden" style="width: 150px; border: 1px solid gray" value="addd" name="type"/>
也应该有id="type"
。
编辑:
顺便说一句,刚刚提到的,这个input
是hidden
。 也许您的switch
应该基于另一个变量,例如$_POST['number']
或其他文本字段?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.