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 />');
  }

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

意外的'{'

大概我做错了什么,不是在使用大括号,而是在使用圆括号......但我看不到在哪里......

4

3 回答 3

4

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

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

将来我建议在复杂的语句中计算你的左括号和右括号,以确保它们是平衡的。

于 2012-12-29T14:36:12.597 回答
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 />');
  }
于 2012-12-29T14:52:30.740 回答
0

(如果必须删除第二个中的第一个

if( isset($_POST['mc']) && isset($_POST['md']) ){ //***
    $error_message .=('You cannot play in both the cadet tournament and mens doubles <br />');
}
于 2012-12-29T15:19:33.003 回答