dongtang1918 2012-06-17 00:04
浏览 150
已采纳

解析错误:语法错误,C:\ wamp \ www eg.php中的意外“{”[关闭]

<html>
<head>
<title>
Registration
</title>
</head>
<?php
if(isset($_POST['submit buttton'])){
    processForm();
}else{
    displayForm();
}


/*check out this function. Here in array doesnot work*/

function validateField($fieldname,$missingfield){
    if(in_array($fieldname,$missingfield)){
        echo 'class = "error"';
    }
}
function setValue($fieldname){
    if(isset($_POST[$fieldname])){
        echo $_POST[$fieldname];
    }
}

function setChecked($fieldname,$fieldvalue){
    if((isset($_POST[$fieldname]) and ($_POST[fieldname] == $fieldvalue)){
        echo 'checked = "checked"';
    }
}
function setSelected( $fieldName, $fieldValue ) {
    if ( isset( $_POST[$fieldName] ) and $_POST[$fieldName] == $fieldValue ) {
        echo ' selected="selected"';
    }
}
function processForm(){
    $requiredfields = ("firstname","lastname","password1","password2","gender");
    $missingfields = array();
    foreach($missingfields as $missingfield){
        if((!isset($_POST[$requiredfield]) or $_POST[$requiredfield]){
            $missingfields[] = $requiredfield ;
        }
    }
    if ( $missingFields ) {
        displayForm( $missingfields );
    } else {
    displayThanks();
    }
}

function displayForm($missingfields){
    <?php
        <h1>Membership Form</h1>
        <?php if ( $missingFields ) { ?>
        <p class="error">There were some problems with the form you submitted.
        Please complete the fields highlighted below and  click Send Details to
        resend the form.</p>
        <?php } else { ?>
        <p>Thanks for choosing to join The Widget Club. To register, please
        fill in your details below and click Send Details. Fields marked with an
        asterisk (*) are required.</p>
    ?>

<?php } ?>

    <form action="registration.php" method="post">
    <div style="width: 30em;">
    <label for="firstName"<?php validateField( "firstName",
                        $missingFields ) ?>>First name *</label>
    <input type="text"  name="firstName" id="firstName"
                        value="<?php setValue( "firstName" ) ?>" />
    <label for="lastName"<?php validateField( "lastName",
$missingFields ) ?>>Last name *</label>
    <input type="text" name="lastName" id="lastName" value=
    "<?php setValue( "lastName" ) ?>" />
    <label for="password1"<?php if ( $missingFields ) echo
    ' class="error"’ ?>>Choose a password *</label>
    <input type="password" name="password1" id="password1" value="" />
    <label for="password2"<?php if ( $missingFields ) echo
    ' class="error"’ ?>>Retype password *</label>
    <input type="password" name="password2" id="password2" value="" />
    <label<?php validateField( "gender", $missingFields ) ?>>Your
    gender: *</label>
    <label for="genderMale">Male</label>
    <input type="radio" name="gender" id="genderMale" value=
    "M"<?php setChecked( "gender", "M" )?>/>
    <label for="genderFemale">Female</label>
    <input type="radio" name="gender" id="genderFemale" value=
    "F"<?php setChecked( "gender", "F" )?> />
    <label for="favoriteWidget">What’s your favorite widget? *</label>
    <select name="favoriteWidget" id="favoriteWidget" size="1">
    <option value="superWidget"<?php setSelected( "favoriteWidget",
    "superWidget" ) ?>>The SuperWidget</option>
    ?>

</html>

On my first run of the file the in_array function doesnt seem to work.I mean functions like isset() are displayed in bold but it seems the in_array function is not detected. The browser displays the error as:

( ! ) Parse error: syntax error, unexpected '{' in C:\wamp\wwweg.php on line 15.

  • 写回答

3条回答 默认 最新

  • doufen9815 2012-06-17 00:07
    关注
    $requiredfields = ("firstname","lastname","password1","password2","gender"); 
    

    This line is invalid. You should have the keyword array before the (.

    In general, use a code editor that has bracket matching. This would help you find missing )}] and extra ({[ more easily. Some even include HTML tag matching in a similar way.

    http://notepad-plus-plus.org/ is a good example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化