PHP中的未定义索引 [英] Undefined index in PHP

查看:257
本文介绍了PHP中的未定义索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
PHP:"Notice:Undefined variable"和"Notice:Undefined index"

Possible Duplicate:
PHP: "Notice: Undefined variable" and "Notice: Undefined index"

美好的一天!

我的代码中出现以下错误:

I am having the following error in my code:

<?php
if (!$_POST['SUBMIT']){   //ERROR: Undefined index
?>
    <H2>Add Employee</H2>
    <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="POST">
    <table width="400" border="0" cellspacing="1" cellpadding="2">
       <tr>
            <td width="100">SSN</td>
            <td><input name="SSN" type="text" id="SSN"></td>
       </tr>
       <tr>
            <td width="100">&nbsp;</td>
            <td><input name="SUBMIT" type="SUBMIT" id="ADD" value="ADD"></td>
       </tr>
    </table>
    </form>
 <?php
    }
    else {
    //code here
    }
?>

如何清除上面的错误?谢谢.

How can I remove the error above? Thank you.

推荐答案

它应该是通知,而不是错误.

It should be a notice and not an error.

要解决的是,您必须检查是否设置了$_POST['submit']:

To fix is you'll have to check whether $_POST['submit'] is set:

if(!isset($_POST['submit'])) {
    ...
}

这篇关于PHP中的未定义索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆