if语句中的括号解析错误

时间:2012-12-29 14:34:09

标签: syntax-error php brackets

尝试对网球锦标赛的注册表格进行一些稍微棘手的表单验证(在本例中为复选框)

<?php 
if ( ( isset($_POST['ms'])&&isset($_POST['ws']) )
        || (isset($_POST['mc'])&&isset($_POST['ws']))
        || (isset($_POST['md'])&&isset($_POST['ws']))
        || (isset($_POST['ms'])&&isset($_POST['wc']))
        || (isset($_POST['ms'])&&isset($_POST['wd']))
        || (isset($_POST['mc'])&&isset($_POST['wc']))
        || (isset($_POST['mc'])&&isset($_POST['wd']))
        || (isset($_POST['md'])&&isset($_POST['wd']))
    ){
      $error_message .=('You can only play as one sex! <br />');
  }


if ( (isset($_POST['mc'])&&isset($_POST['md']) ) { //***
  $error_message .=('You cannot play in both the cadet tournament and mens doubles <br />');
  }

但是,这会导致带有三个星号的行的解析错误。

  

意外的'{'

据推测,我做错了什么,不是使用花括号,而是使用圆括号......但是我看不到...

3 个答案:

答案 0 :(得分:4)

您在第二个if语句中缺少结束括号,请使用:

if ((isset($_POST['mc']) && isset($_POST['md']))) 

将来我会建议在复杂的陈述中计算你的开始和结束括号,以确保它们是平衡的。

答案 1 :(得分:0)

<?php 
if((isset($_POST['ms']) && isset($_POST['ws']))
        || (isset($_POST['mc'])&&isset($_POST['ws']))
        || (isset($_POST['md'])&&isset($_POST['ws']))
        || (isset($_POST['ms'])&&isset($_POST['wc']))
        || (isset($_POST['ms'])&&isset($_POST['wd']))
        || (isset($_POST['mc'])&&isset($_POST['wc']))
        || (isset($_POST['mc'])&&isset($_POST['wd']))
        || (isset($_POST['md'])&&isset($_POST['wd']))
    )){

      $error_message .=('You can only play as one sex! <br />');
  }


if((isset($_POST['mc']) && isset($_POST['md'])){ //***

    $error_message .=('You cannot play in both the cadet tournament and mens doubles <br />');
  }

答案 2 :(得分:0)

必须删除第一个(,如果必须删除

if( isset($_POST['mc']) && isset($_POST['md']) ){ //***
    $error_message .=('You cannot play in both the cadet tournament and mens doubles <br />');
}