-1

Warning: Undefined array key "Required" on line 15

Here's my code.

$RequiredMail = $Required = "";

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (filter_var($_POST["Required"])) {  <--------Line 15
        $RequiredMail = "De email dient ingevult te worden";
    } else {
        $Required = test_input($_POST["E-mail"]);
    }

it might be obvious to some, but i'm bashing my head against a wall. i haven't made an array yet and don't know how to implement it inside of my code.

If there are any videos / books / recommendations all is appreciated. Could someone explain this to me as if i am a dummy?

Leeroy
  • 11
  • 3
  • 1
    In your HTML form, do you have any `` with the attribute `name="Required"` ? – Cid May 18 '21 at 13:53
  • this might help you understand the [basics](https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data)... – berend May 18 '21 at 14:02
  • I think you are posting $_POST["Required"] from some other file. If you can provide that, we will see the problem! – user27976 May 18 '21 at 15:47
  • How do i add all of the code to the one i already posted? sorry guys OP is a noob and new to SO – Leeroy May 18 '21 at 18:21
  • Cid you are a hero! i indeed missed the – Leeroy May 18 '21 at 18:28

1 Answers1

0

Is this just typo? Shouldn't you be testing for $_POST["E-mail"] instead of $_POST["Required"] on line 15? So try:

$RequiredMail = $Required = "";

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (filter_var($_POST["E-mail"])) {
        $RequiredMail = "De email dient ingevult te worden";
    } else {
        $Required = test_input($_POST["E-mail"]);
Rzz
  • 1
  • This doesn't make sense. If `filter_var` is returning `false` it means that `$_POST["E-mail"]` is either empty or zero. To me it seems like OP wants to use `E-mail` if `Required` is empty. – El_Vanja May 18 '21 at 14:44
  • El_Vanja is right, i do want to return if empty, yet it says that i made an undefined array key,(which makes me think to add an array but wouldn't this be a hassle?) and should i show all of the code? – Leeroy May 18 '21 at 18:19