2011-06-22 55 views
1

是的我相信我已经完成了,但我收到一条消息,说106线上的C:\ wamp \ www \ contactform.php中的解析错误:解析错误,意外$结束。在那条线上。唯一想到的是我能想到的是,else,如果是错误的,我一直在试图切换它们,看看是否会有所不同。但到目前为止还没有。在PHP中读取错误

</style> 
    </head> 
    <body> 
    <div id="container"> 
    <?php 
    if (isset($_POST['submit'])){ 
     if (trim($_POST['name'])==""){ 
      $strMessage="Please enter your name!"; 
      showForm($strMessage); 
     } elseif (isset($_POST['submit'])){ 
       if (trim($_POST['email'])==""){ 
        $strMessage="Please enter your email!"; 
        showForm($strMessage); 
       } 
       if(isset($_POST['submit'])){ 
        if (trim($_POST['username'])==""){ 
         $strMessage="Please enter your username!"; 
         showForm($strMessage); 
        } elseif ($_POST['pword1'] != $_POST['pword2']) { 
         $_POST['pword1'] = NULL; // Reset the values of pword1 so it is not in the form 
         $_POST['pword2'] = NULL; // Reset the values of pword2 so it is not in the form 
         $strMessage="Passwords do not match!"; 
         showForm($strMessage); 
        } elseif (strlen(trim($_POST['pword1']))<=3){ 
         $strMessage="Your password must be at least 4 characters long!"; 
         showForm($strMessage); 
        } else { 
         $strMessage="Thank you, your information has been submitted. Below is the  information you sent:"; 
         $strMessageBody.="Name: ".trim(stripslashes($_POST['name']))."<br />"; 
         $strMessageBody.="E-mail: ".trim(stripslashes($_POST['Email']))."<br />"; 
         $strMessageBody.="UserName: ".trim(stripslashes($_POST['username']))."<br />"; 
         $strMessageBody.="Password: ".trim(stripslashes($_POST['pword1']))."<br />"; 
         $strMessageBody.="Re-enter Password: ".trim(stripslashes($_POST['pword2']))."<br />"; 
         echo "<h1>".$strMessage."</h1>"; 
         echo $strMessageBody; 
        } 
       } else { 
        $strMessage= "Please fill out the form below to send your information:"; 
        showForm($strMessage); 
       } 
      } 
     ?> 
    </div> 
    </body> 
     </html> 
+3

你应该学会更好的缩进。 (使用软标签进行缩进)很难读取您的代码。你可能在某处有一个缺失的大括号。正确缩进你的代码;它可以帮助团队环境中的其他开发人员,即使你是独自一人,它仍然会帮助你。 – FinalForm

+3

您错过了一个右大括号。编程不是随机切换的。 – Jon

+3

第87行的'else'前的'.'是什么? – rid

回答

3

我相信这是你想要的。你一直在重复“if(isset($ _ POST ['submit'])){”两次太多!

if (isset($_POST['submit'])){ 
    if (trim($_POST['name'])==""){ 
    $strMessage="Please enter your name!"; 
    showForm($strMessage); 
    } elseif (trim($_POST['email'])==""){ 
     $strMessage="Please enter your email!"; 
    showForm($strMessage); 
    } elseif (trim($_POST['username'])==""){ 
    $strMessage="Please enter your username!"; 
    showForm($strMessage); 
    } elseif ($_POST['pword1'] != $_POST['pword2']) { 
    $_POST['pword1'] = NULL; // Reset the values of pword1 so it is not in the form 
    $_POST['pword2'] = NULL; // Reset the values of pword2 so it is not in the form 
    $strMessage="Passwords do not match!"; 
    showForm($strMessage); 
    } elseif (strlen(trim($_POST['pword1']))<=3){ 
    $strMessage="Your password must be at least 4 characters long!"; 
    showForm($strMessage); 
    } else { 
    $strMessage="Thank you, your information has been submitted. Below is the  information you sent:"; 
    $strMessageBody.="Name: ".trim(stripslashes($_POST['name']))."<br />"; 
    $strMessageBody.="E-mail: ".trim(stripslashes($_POST['Email']))."<br />"; 
    $strMessageBody.="UserName: ".trim(stripslashes($_POST['username']))."<br />"; 
    $strMessageBody.="Password: ".trim(stripslashes($_POST['pword1']))."<br />"; 
    $strMessageBody.="Re-enter Password: ".trim(stripslashes($_POST['pword2']))."<br />"; 
    echo "<h1>".$strMessage."</h1>"; 
    echo $strMessageBody; 
    } 
} else { 
    $strMessage= "Please fill out the form below to send your information:"; 
    showForm($strMessage); 
} 
+0

我开始了这个“项目”一分钟然后保释出来。 +1努力,但检查你的'elsif's,PHP需要'elseif' –

+0

谢谢,我知道我做错了什么。 – andy

+0

@韦斯利Tnx! 'elsif's改成'elseif' – Jochem

2

one closing} is missing。唯一的问题是在哪里?如果你把它放在前面?>解析错误将会消失,但我不确定这是否是一个无用的地方。取决于你的困难逻辑。

+0

如果你仔细观察代码(不容易,我知道),你会发现很有可能,在对代码本身进行一些解释时,问题会更深入一些(请参阅我的答案)。 – Jochem