Undefine index, please help... please :(

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I installed php4 for apached and restart apache afterward. but my little
php script generated error followint error:
PHP Notice:  Undefined index:  myname in
/usr/local/www/data-dist/www.authtec.com/php-test.php on line 2

I was trying to run the following php script in apache:

if($_POST["myname"]) {
                 print "Hello, ".$_POST["myname"]."<p>\n"
} else {
<form method="post" action="php-test.php">
<input type=input type=text name=myname>
<textarea cols=20 rows=4 wrap=virtual name=textbox></textarea>
<input type=submit value="Submit">

What could be wrong with my configuration? and how can I fix it?


Re: Undefine index, please help... please :(

sam wrote:

Quoted text here. Click to load it

You are getting a notice, not an error. Do this instead:
and your notice will be gone.

Re: Undefine index, please help... please :(


You should _always_ make sure a key exists in an array before using it.

if (array_key_exists('myname', $_POST) ) {
    echo "<p>Hello, ", $_POST['myname'], "</p>";

I also would suggest a function which looks in both $_POST and $_GET for a
parameter, unescaping it if necessary.

La'ie Techie

Site Timeline