2011-11-26 52 views
-8

我尝试建立一个使用HTML和PHP的联系表格,但我得到这个消息解析错误:,语法错误,意想不到的T_ELSE在c:\ xampp \ htdocs \ myfolder \ form_process.php上线81,我真的不知道在哪里即时做错了,这是低于语法错误,意外的T_else在线81

<?php 

    session_start(); 

     if($_POST['submit']) 
     { 
     $num = 0; 

     if(strlen($_POST['name']) > 0) 
     $num = $num; 
     $_SESSION['name'] = $_POST['name']; 
     unset($_SESSION['error_name']); 
     } 
     else 
     { 
     $num = $num + 1; 
     $_SESSION['error_name'] = "You have not filled out a Name"; 

     } 

     if(strlen($_POST['surname']) > 0){ 
     $num = $num; 
     $_SESSION['surname'] = $_POST['surname']; 
     unset($_SESSION['error_surname']); 
     } 

     else 
     { 
     $num = $num + 1; 
     $_SESSION['error_surname'] = "You have not filled out a Surname"; 

     } 

     if(strlen($_POST['phone']) > 0){ 
     $num = $num; 
     $_SESSION['phone'] = $_POST['phone']; 
     unset($_SESSION['error_phone']); 
     } 
     else 
     { 
     $num = $num + 1; 
     $_SESSION['error_phone'] = "You have not filled out a Phone Number"; 

     } 

     if(strlen($_POST['email']) > 0){ 
     $num = $num; 
     $_SESSION['email'] = $_POST['email']; 
     unset($_SESSION['error_email']); 
     } 
     else 
     { 
     $num = $num + 1; 
     $_SESSION['error_email'] = "You have not filled out a Email Address"; 

     } 

     if(strlen($_POST['comments']) > 0){ 
     $num = $num; 
     $_SESSION['comments'] = $_POST['comments']; 
     unset($_SESSION['error_comments']); 
     } 
     else 
     { 
     $num = $num + 1; 
     $_SESSION['error_comments'] = "You have not filled out a Comment"; 

     } 

     if ($num == 0) 
      { 
      //process form 
      echo "success"; 
      } 
      else 
      { 
      header("Location: inter.php");  
      } 


    else{ 

     header("location: inter.php"); 
     } 

    ?> 

有人帮助你的代码的

+5

什么是线81? – BoltClock

+3

如果您正确缩进代码,您将立即看到此类错误。 – Dalmas

+1

这个问题似乎是无关紧要的,因为它是关于调试代码的。 – HamZa

回答

2

底部我的代码有一个未关闭的if语句。检查你的代码。

if{ 

... 

}else{ 
    header("location: inter.php"); 
} 
+0

非常感谢,但即时通讯获得另一个错误的形式是不按照其应该的方式工作,如果我点击提交按钮,它会将我重定向到主页,如果我回到联系人,当它显示我没有输入任何东西,如果我点击resert按钮它没有做任何事情 – thequantumtheories

+0

这是一个不同的问题。如果你仍然没有得到同样的错误,请接受其中一个答案,然后向另一个答复问你的问题。我不能真正回答你的问题,因为我不知道你的代码处理你的表单。 – tuze

0

我认为你缺少一个括号

 header("Location: inter.php");  
    } 

} // This one is missing 
else { 
0

我这个你错过了就行了if(strlen($_POST['name']) > 0)开括号,它应该开始:

<?php 

session_start(); 

if($_POST['submit']) 
{ 
    $num = 0; 

    if(strlen($_POST['name']) > 0) 
    { // added a brace here 
     $num = $num; 
     $_SESSION['name'] = $_POST['name']; 
     unset($_SESSION['error_name']); 
    } 
    else 

你可以通过确保代码有条理地布置,或者使用显示匹配大括号的编辑器,可以更轻松地找到这样的事情。

+0

非常感谢,但即时通讯获取另一个错误的形式是不按照它应该的方式工作,如果我点击提交按钮,它会将我重定向到主页,如果我回到联系人,当它显示我没有输入任何东西,如果我点击resert按钮它没有做任何事情 – thequantumtheories

+0

也许你的表单不是由POST('method =“post”')提交,或者你没有提交'$ _POST ['submit' ]'('')。 –

+0

即时通讯使用相同的方法是好的,如果你可以给我你的电子邮件地址,以便我发送你的整个,如果你不介意吗?我的电子邮件是[email protected]即时通讯类新的PHP和即时通讯尝试建立一个简单的网站 – thequantumtheories

1

else { header("location: inter.php"); }是不与任何其他:)

你一定要使用一致的缩进,始终把你的大括号平衡。

这里有一个更新,与(失踪?)大括号:

<?php 
    session_start(); 

    if($_POST['submit']) { 
    $num = 0; 

    if(strlen($_POST['name']) > 0) { 
     $num = $num; 
     $_SESSION['name'] = $_POST['name']; 
     unset($_SESSION['error_name']); 
    } 
    else { 
     $num = $num + 1; 
     $_SESSION['error_name'] = "You have not filled out a Name"; 

    } 

    if(strlen($_POST['surname']) > 0){ 
     $num = $num; 
     $_SESSION['surname'] = $_POST['surname']; 
     unset($_SESSION['error_surname']); 
    } 
    else { 
     $num = $num + 1; 
     $_SESSION['error_surname'] = "You have not filled out a Surname"; 

    } 

    if(strlen($_POST['phone']) > 0){ 
     $num = $num; 
     $_SESSION['phone'] = $_POST['phone']; 
     unset($_SESSION['error_phone']); 
    } 
    else { 
     $num = $num + 1; 
     $_SESSION['error_phone'] = "You have not filled out a Phone Number"; 
    } 

    if(strlen($_POST['email']) > 0){ 
     $num = $num; 
     $_SESSION['email'] = $_POST['email']; 
     unset($_SESSION['error_email']); 
    } 
    else { 
     $num = $num + 1; 
     $_SESSION['error_email'] = "You have not filled out a Email Address"; 
    } 

    if(strlen($_POST['comments']) > 0){ 
     $num = $num; 
     $_SESSION['comments'] = $_POST['comments']; 
     unset($_SESSION['error_comments']); 
    } 
    else { 
     $num = $num + 1; 
     $_SESSION['error_comments'] = "You have not filled out a Comment"; 
     } 

    if ($num == 0) { 
      //process form 
      echo "success"; 
    } 
    else { 
      header("Location: inter.php");  
    } 
    } 
    else { 
     header("location: inter.php"); 
    } 
    ?> 
0

There's 2 else of same if

if ($num == 0) 
      { 
      //process form 
      echo "success"; 
      } 
      else 
      { 
      header("Location: inter.php");  
      } 


    else{ 

     header("location: inter.php"); 
     } 

    ?> 
+0

非常感谢,但即时通讯获取另一个错误表单不按照其应该的方式工作,如果我点击提交按钮,它会将我重定向到主页,如果我回到联系人那当它显示我没有进入任何东西,如果我点击resert按钮它没有做任何事情 – thequantumtheories