【发布时间】:2011-08-06 07:47:07
【问题描述】:
可能重复:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”
美好的一天!
我的代码中出现以下错误:
<?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"> </td>
<td><input name="SUBMIT" type="SUBMIT" id="ADD" value="ADD"></td>
</tr>
</table>
</form>
<?php
}
else {
//code here
}
?>
如何消除上述错误?谢谢。
【问题讨论】:
-
尝试执行
print_r($_POST)或var_dump($_POST)并首先查看数组中的内容 -
尝试使用
isset()和!empty而不是!$_POST。
标签: php