-2

我定义了一个$_POST索引,但收到未定义的错误消息。

这是代码:

 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']
        );
4

4 回答 4

1

适用isset()于您的每个$_POST如果:

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']
);
于 2013-01-02T08:56:45.977 回答
1

你也可以这样使用。

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']
            );
          }
于 2013-01-02T08:59:12.630 回答
0

首先,我建议检查 html 本身,我假设该方法设置为 POST,因为其他方法都在工作,但请仔细检查以确保安全!然后,另一个大错误是您在输入时输入名称字段时搞砸了。检查 html 上的所有名称以确保它们拼写正确。此外,请确保您拥有所有结束标签和开始标签,以及开始/结束引号。

也不要忘记将 isset() 添加到上面的所有内容中。您还可以创建更好的功能,例如,

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

这将检查它是否为空字符串,以及是否已定义。很有用。如果您愿意,也可以通过 return trim($var) 来使用它来修剪。

于 2013-01-02T09:59:41.423 回答
0

你可以这样写——

 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']
        );
于 2013-01-02T08:56:48.300 回答