0

The error can be seen in the title. "undefined index" I am wondering the reason for these errors as it was working in school but at home it doesn't... Sorry im pretty new to this ive looked and was hoping for an explanation/solution in plain terms if you can please! Many thanks!

(in 1 document)

$id=$_POST['id'];
$a_name=$_POST['a_name'];
$a_email=$_POST['a_email'];
$a_answer=$_POST['a_answer'];

(in another document)

$id=$_GET['id'];

If you need any more information please ask i can post more code and data base stuff if needed!

  • It works without notices on another computer because the [`php.ini`](http://php.net/manual/en/ini.list.php) configuration [`error_reporting`](http://php.net/manual/en/errorfunc.configuration.php#ini.error-reporting) is probably set to `E_ALL & ~E_NOTICE` while on your computer it is probably set to `E_ALL`. Keep it on `E_ALL` as many issues that PHP reports as "notices" are, in fact, programming errors. – axiac Dec 08 '17 at 20:33
  • Oh, ok thats interesting! The only other thing is that in school my output would work however at home there is no output. What would this be to do with do you know? –  Dec 08 '17 at 21:14

1 Answers1

0

This error means that there is nothing in the $_POST array with a key you're asking for.

If you have an array that looks like this:

$myArray = array (
    'a' => 1,
    'b' => 2,
    'c' => 3
);

You would get this error if you do:

$value = $myArray['d'];

Because the key 'd' does not exist in that array.

Make sure all of your form elements have a name attribute. The name should match the values you're using as your array keys (id, a_name, a_email, a_answer).

flip
  • 555
  • 3
  • 8
  • hmmmm name="a_name" name="a_email" name="a_answer" name="id" This is what i have in another document where you actually fill in the fields. They all have the correct names... –  Dec 08 '17 at 20:42
  • Any other possibility or suggestion? –  Dec 08 '17 at 20:51
  • After you've submitted the form, do a var_dump($_POST) or a print_r($_POST) to see what values you get there. If they're not being posted then it could be a problem with your form. – flip Dec 11 '17 at 13:47