我定义了$_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']
);
答案 0 :(得分:1)
在if:
中的每个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']
);
答案 1 :(得分: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']
);
}
答案 2 :(得分: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']
);
答案 3 :(得分:0)
首先,我建议检查html本身,我假设该方法设置为POST,因为其余的都在工作,但仔细检查是安全的!然后,另一个大错误是你在输入上输入名字字段时搞砸了。检查html上的所有名称,确保它们拼写正确。此外,请确保您拥有所有结束标记和开始标记,以及打开/关闭引号。
另外不要忘记将isset()添加到上面的所有内容中。你也可以创建一个更好的功能,如
function checkSet($var){
if(isset($var) && $var != ""){
return $var;
}else{
return false;
}
}
这将检查它是否为空字符串,以及是否已定义。很有用。如果您喜欢,还可以通过返回修剪($ var)来修剪它。