2011-06-22 56 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