1

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

Hi my question relates to PHP and getting echo to work.

Background info:

My Php version is 5.4.3

Problem:

My problem is that I have been having trouble passing data from my html form to a php script and getting it to run. I can enter and submit text into the html form, but when I submit it to the PHP script it doesn't work. The next page either just displays HTML or a PHP undefined index error message.

I reset my wamp server and it solved the issue with only the html was being displayed. However, the PHP undefined index error continues to occur.

The undefined index error occurs on line 8 (the first line of the php code. right after the opening php where i try to create the variable).

The only time it works is when I set name in the html form to "vv" and set the post data in the php form to "vv". VV was selected totally at random.

Any help you can provide would be MUCH appreciated.

CODE:

HTML FORM

<form method="post" action="report2.php">
        <label for="when">When did it happen</label>
        <input type="text" id="when" name="when" />
        <br />
        <input type="submit" value="submit" name="submit" />
</form>

PHP Script

<body>
    <h1>Aliens Abducted Me - Report an Abduction</h1>
    <?php
        $when = $_POST['when'];

        echo 'You were abducted on ' . $when;
    ?>
</body>
Community
  • 1
  • 1

1 Answers1

-1

Drew,

Try this:

<?php
        $when = 'hello';

        echo $when;
?>

Just to see if your localhost is working. Also try a free web hosting (php hosting) to eliminate your local server issue.

Jim

jim dif
  • 641
  • 1
  • 8
  • 17