-2

I have a $_POST index defined but get the error-message that it's not defined.

Here's the code:

 if (isset($_POST['submit']) AND ($_POST['userid']) AND ($_POST['firstname']) AND ($_POST['lastname']) AND ($_POST['address']) AND ($_POST['ZIP']) AND ($_POST['phonenumber']) AND ($_POST['mail']) AND ($_POST['group']))
       {
        $result = $this->sendEmail(
           $_POST['userid'], 'mail@mymail.com', 'mail@mymail.com', $_POST['firstname'], $_POST['lastname'], $_POST['address'], $_POST['ZIP'], $_POST['phonenumber'], $_POST['mail'], $_POST['group']
        );
j0k
  • 22,600
  • 28
  • 79
  • 90
Krystian
  • 85
  • 2
  • 11

4 Answers4

1

Apply isset() on each $_POST inside your if:

if (isset($_POST['submit']) AND 
    isset($_POST['userid']) AND
    isset($_POST['firstname']) AND
    isset($_POST['lastname']) AND
    isset($_POST['address']) AND
    isset($_POST['ZIP']) AND
    isset($_POST['phonenumber']) AND
    isset($_POST['mail']) AND
    isset($_POST['group']))
{
  $result = $this->sendEmail(
    $_POST['userid'],
    'mail@mymail.com',
    'mail@mymail.com',
    $_POST['firstname'],
    $_POST['lastname'],
    $_POST['address'],
    $_POST['ZIP'],
    $_POST['phonenumber'],
    $_POST['mail'],
    $_POST['group']
);
j0k
  • 22,600
  • 28
  • 79
  • 90
1

You can use like this also.

if (isset($_POST['submit']) && isset($_POST['userid']) && isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['address']) && isset($_POST['ZIP']) && isset($_POST['phonenumber']) && isset($_POST['mail']) && isset($_POST['group']))

           {
               $result = $this->sendEmail(
               $_POST['userid'], 'mail@mymail.com', 'mail@mymail.com', $_POST['firstname'], $_POST['lastname'], $_POST['address'], $_POST['ZIP'], $_POST['phonenumber'], $_POST['mail'], $_POST['group']
            );
          }
Kaspar Mary
  • 126
  • 1
  • 11
0

You can write like this-

 if (isset($_POST['submit']) AND 
        isset($_POST['userid']) AND $_POST['userid'] != "" AND 
        isset($_POST['firstname']) AND $_POST['firstname'] != "" AND 
        isset($_POST['lastname']) AND $_POST['lastname']!= "" AND 
        isset($_POST['lastname']) AND $_POST['lastname']!= "" AND 
        isset($_POST['address']) AND $_POST['address'] != "" AND 
        isset($_POST['ZIP']) AND $_POST['ZIP'] != "" AND 
        isset($_POST['phonenumber']) AND $_POST['phonenumber'] != "" AND 
        isset($_POST['mail']) AND $_POST['mail'] != "" AND 
        isset($_POST['group']) AND $_POST['group'] != "")
       {
        $result = $this->sendEmail(
           $_POST['userid'], 'mail@mymail.com', 'mail@mymail.com', $_POST['firstname'], $_POST['lastname'], $_POST['address'], $_POST['ZIP'], $_POST['phonenumber'], $_POST['mail'], $_POST['group']
        );
Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
0

First off, I recommend checking on the html itself, I assume that the method is set to POST since the rest are working, but double check to be safe! Then, another big mistake is that you screwed up when typing the name field on an input. check all names on the html to be sure they're spelled correctly. Also, make sure you have all your closing tags and opening tags, as well as opening/closing quotes.

Also don't forget to add the isset() to all the things above. Also you could create a better function like,

function checkSet($var){
       if(isset($var) && $var != ""){
            return $var;
       }else{
            return false;
       }
}

this will check if it's and empty string, and if it's defined. Very useful. You can also use it to trim by doing return trim($var) if you fancy.

samuraiseoul
  • 2,888
  • 9
  • 45
  • 65