语法错误,意外的T
我试图建立一个使用HTML和PHP的联系表格,但我得到这个消息解析错误:,语法错误,意想不到的T_ELSE在C: xampp htdocs myfolder form_process.php 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");
      }
    ?>
有人帮忙
您的代码底部有一个未公开的if语句。 检查你的代码。
if{  
...
}else{
    header("location: inter.php");
} 
  你的else { header("location: inter.php"); }  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");
  }
  ?>
我想你错过了一个括号
        header("Location: inter.php");      
    }
} // This one is missing
else {
上一篇: syntax error,unexpected T
下一篇: Parse error: syntax error, unexpected '[', expecting ')' php
