Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined index in PHP [duplicate]

Tags:

php

Possible Duplicate:
PHP: “Notice: Undefined variable” and “Notice: Undefined index”

Good day!

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.

like image 540
newbie Avatar asked Apr 15 '11 12:04

newbie


1 Answers

It should be a notice and not an error.

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

if(!isset($_POST['submit'])) {
    ...
}
like image 199
halfdan Avatar answered Oct 17 '22 02:10

halfdan