尝试添加第4个else语句,但它无效。无法找到有效的在线示例。前3个陈述有效,但不是第4个。应该是If,elseif,elseif,else还是If,elseif,else,else?
if(empty($fromName) or empty($fromEmail) or empty($subject) or empty($comments)) {
echo 'You cannot submit the form with empty fields. Please correct the form and resubmit.';
return false;
}
elseif($fieldDelete == "Delete this text!"){
$msg ="Delete the contents of the fourth field before submitting.";
print $msg;
}
else {
$flgchk = mail ("$to", "$subject", "$message", "$headers");
$imgfile = "images/NatMap logo2.gif";
$handle = fopen($filename, "r");
$imgbinary = fread(fopen($imgfile, "r"), filesize($imgfile));
echo '<img src="data:image/gif;base64,' . base64_encode($imgbinary) . '" width=427 height=72 />';
echo "\n<br />\n<br />Thank You! An e-mail has been sent to the National Map web team and they will get back to you in the next 24-48 hours.";
}
else ($fieldDelete == "Delete this text!"){
$msg ="Delete the contents of the fourth field before submitting.";
print $msg;
}
答案 0 :(得分:1)
上一次if
声明没有else
。它看起来应该类似于:
if (condition1) {
/* ... */
}
elseif (condition2) {
/* ... */
}
elseif (condition3) {
/* ... */
}
else {
/* ... */
}
答案 1 :(得分:0)
$ fromName ==您无法将else
加入else
。将其更改为else if
。例如:
if(empty($fromName) or empty($fromEmail) or empty($subject) or empty($comments)) {
echo 'You cannot submit the form with empty fields. Please correct the form and resubmit.';
return false;
}elseif($fieldDelete == "Delete this text!"){
$msg ="Delete the contents of the fourth field before submitting.";
print $msg;
}elseif($fromName == "Curtisvien" || $fromName == "RichardMark" || $fromName == "Thomastymn"){
$msg ="You are blocked."; print $msg;
}else{
$flgchk = mail ("$to", "$subject", "$message", "$headers");
$imgfile = "images/NatMap logo2.gif";
$handle = fopen($filename, "r");
$imgbinary = fread(fopen($imgfile, "r"), filesize($imgfile));
echo '<img src="data:image/gif;base64,' . base64_encode($imgbinary) . '" width=427 height=72 />';
echo "\n<br />\n<br />Thank You! An e-mail has been sent to the National Map web team and they will get back to you in the next 24-48 hours.";
}
答案 2 :(得分:0)
你不能使用其他两次。如下所示,将第二个最后一个更改为else,如下所示:
if(empty($fromName) or empty($fromEmail) or empty($subject) or empty($comments)) {
echo 'You cannot submit the form with empty fields. Please correct the form and resubmit.';
return false;
}
elseif($fieldDelete == "Delete this text!"){
$msg ="Delete the contents of the fourth field before submitting.";
print $msg;
}
elseif {
$flgchk = mail ("$to", "$subject", "$message", "$headers");
$imgfile = "images/NatMap logo2.gif";
$handle = fopen($filename, "r");
$imgbinary = fread(fopen($imgfile, "r"), filesize($imgfile));
echo '<img src="data:image/gif;base64,' . base64_encode($imgbinary) . '" width=427 height=72 />';
echo "\n<br />\n<br />Thank You! An e-mail has been sent to the National Map web team and they will get back to you in the next 24-48 hours.";
}
else ($fieldDelete == "Delete this text!"){
$msg ="Delete the contents of the fourth field before submitting.";
print $msg;
}
答案 3 :(得分:0)
这不是写入.... elseif ... else语句的正确方法。 你应该写下面的内容:
if()
{
//statement;
}elseif()
{
//statement;
}elseif()
{
if()
{
//Nested Statement;
}else{
//Nested Statement;
}
}else{
//If all of above is false then this will execute ;
}
在那里你可以使用相同的进程使用任意数量的elseif条件。
答案 4 :(得分:0)
也许您正在尝试这样做:
if (condition1) {
do_this;
} else {
if (condition2) {
do_that;
} else {
do_something_else;
}
}
答案 5 :(得分:0)
if(empty($fromName) or empty($fromEmail) or empty($subject) or empty($comments)) {
echo 'You cannot submit the form with empty fields. Please correct the form and resubmit.';
return false;
}
elseif($fieldDelete == "Delete this text!"){
$msg ="Delete the contents of the fourth field before submitting.";
print $msg;
}
elseif (($fromName == "Curtisvien") || ($fromName == "Thomastymn") || ($fromName == "RichardMark")) {
$msg ="You are blocked.";
print $msg;
}
else {
$flgchk = mail ("$to", "$subject", "$message", "$headers");
$imgfile = "images/NatMap logo2.gif";
$handle = fopen($filename, "r");
$imgbinary = fread(fopen($imgfile, "r"), filesize($imgfile));
echo '<img src="data:image/gif;base64,' . base64_encode($imgbinary) . '" width=427 height=72 />';
echo "\n<br />\n<br />Thank You! An e-mail has been sent to the National Map web team and they will get back to you in the next 24-48 hours.";
}