错误到我的PHP代码结束,我找不到它,我已经尝试了两天

时间:2014-01-14 03:13:47

标签: php

链接到基本功能文件:

<?php require_once("functions.inc"); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <link rel="stylesheet" type="type/css" href="form.css"/>
    <title>Registration Page</title>
    </head>
    <body>
    <form id="userForm" method="POST" action="register-process.php">
    <div>

注册页面

    <fieldset>
            <legend>Registration Information</legend>
            <div id="errorDiv">

    <?php
            if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) {
                    unset($_SESSION['formAttempt']);
                    print "Errors encountered<br />\n";
                    foreach ($_SESSION['error'] as $error) {
                                    print $error . "<br />\n";
                    } //end foreach
    ?>

    </div>

注册页面字段:

            <label for="fname">First Name:* </label>
                    <input type="text" id="fname" name="fname" />
                    <span class="errorFeedback errorSpan"
            id="fnameError"> First Name is required</span>
                    <br />
                    <label for="lname">Last Name:* </label>
                    <input type="text" id="lname" name="lname">
                    <span class="errorFeedback errorSpan"
            id="lnameError">Last Name is required</span>
                    <br />
                    <label for="email">E-mail Address:*</label>
                    <input type="text" id="email" name="email">
                    <span class="errorFeedback errorSpan"
            id="emailError">E-mail is required</span>
                    <br />
                    <label for="password1">Password:*</label>
                    <input type="password" id="password1" name="password1">                             <span class="errorFeedback errorSpan"
            id="password1Error">Password required</span>
                    <br /> 
                    <label for="password2">Verify Password:*</label>
                    <input type="password" id="password2" name="password2">
                    <span class="errorFeedback errorSpan"
            id="password1Error">Password required</span>
                    <br />
                    <label for="addr">Address: </label>
                    <input type="text" id="addr" name="addr">
                    <br />
                    <label for="city">City:</label>
                    <input type="text" id="city" name="city">
                    <br />
                    <label for="county">County:</label>
                    <select name="county" id="county">
                    <option></option>
                    <option value="Avon">Avon</option>
                    <option value="Bedfordshire">Bedfordshire</option>
                    <option value="Berkshire">Berkshire</option>
                    <option value="Borders">Borders</option>
                    <option value="Buckinghamshire">Buckinghamshire</option>
                    <option value="Cambridgeshire">Cambridgeshire</option>
                    <option value="Central">Central</option>
                    <option value="Cheshire">Cheshire</option>
                    <option value="Cleveland">Cleveland</option>
                    <option value="Clwyd">Clwyd</option>
                    <option value="Cornwall">Cornwall</option>
                    <option value="County Antrim">County Antrim</option>
                    <option value="County Armagh">County Armagh</option>
                    <option value="County Down">County Down</option>
                    <option value="County Fermanagh">County Fermanagh</option>
                    <option value="County Londonderry">County Londonderry</option>
                    <option value="County Tyrone">County Tyrone</option>
                    <option value="Cumbria">Cumbria</option>
                    <option value="Derbyshire">Derbyshire</option>
                    <option value="Devon">Devon</option>
                    <option value="Dorset">Dorset</option>
                    <option value="Dumfries and Galloway">Dumfries and Galloway</option>
                    <option value="Durham">Durham</option>
                    <option value="Dyfed">Dyfed</option>
                    <option value="East Sussex">East Sussex</option>
                    <option value="Essex">Essex</option>
                    <option value="Fife">Fife</option>
                    <option value="Gloucestershire">Gloucestershire</option>
                    <option value="Grampian">Grampaign</option>
                    <option value="Greater Manchester">Greater Manchester</option>
                    <option value="Gwent">Gwent</option>
                    <option value="Gwynedd County">Gwynedd County</option>
                    <option value="Hampshire">Hampshire</option>
                    <option value="Herefordshire">Herefordshire</option>
                    <option value="Hertfordshire">Hertfordshire</option>
                    <option value="Highlands and Islands">Highlands and Islands</option>
                    <option value="Humberside">Humberside</option>
                    <option value="Isle of Wight">Isle of Wight</option>
                    <option value="Kent">Kent</option>
                    <option value="Lancashire">Lancashire</option>
                    <option value="Leicestershire">Leicestershire</option>
                    <option value="Lincolnshire">Licolnshire</option>
                    <option value="Lothian">lothian</option>
                    <option value="Merseyside">Merseyside</option>
                    <option value="Mid Glamorgan">Mid Glamorgan</option>
                    <option value="Norfolk">Norfolk</option>
                    <option value="North Yorkshire">North Yorkshire</option>
                    <option value="Northamptonshire">Northhamptonshire</option>
                    <option value="Northumberland">Northumberland</option>
                    <option value="Nottinghamshire">Nottinghamshire</option>
                    <option value="Oxfordshire">Oxforshire</option>
                    <option value="Powys">Powys</option>
                    <option value="Rutland">Rutland</option>
                    <option value="Shropshire">Shropshire</option>
                    <option value="Somerset">Somerset</option>
                    <option value="South Glamorgan">South Glamorgan</option>
                    <option value="South Yorkshire">South Yorkshire</option>
                    <option value="Staffordshire">Staffordshire</option>
                    <option value="Strathclyde">Strathclyde</option>
                    <option value="Suffolk">Suffolk</option>
                    <option value="Surrey">Surrey</option>
                    <option value="Teesside">Teesside</option>
                    <option value="Tyne and Wear">Tyne and Wear</option>
                    <option value="Warwickshire">Warwickshire</option>
                    <option value="West Glamorgan">West Glamorgan</option>
                    <option value="West Midlands">West Midlands</option>
                    <option value="West Sussex">West Sussex</option>
                    <option value="West Yorkshire">West Yorkshire</option>
                    <option value="Wiltshire">Wiltshire</option>
                    <option value="Worcestershire">Worcestershire</option>
                    </select>
                    <br />
                    <label for="postcode">Postcode:</label>
                    <input type="text" id="postcode" name="postcode">
                    <br />
                    <label for="phone">Phone Number:</label>
                    <input type="text" id="phone" name="phone">
                    <span class="errorFeedback errorSpan"
            id="phoneError">Format: xxxx-xxx-xxxx</span>
                    <br />
                    <br />
                    <label for="mobile"> Number Type:</label>
                    <input class="radioButton" type="radio"        
            name="phonetype" id="mobile" value="mobile">  
                    <label class="radioButton" for="mobile">Mobile</label>
                    <input class="radioButton" type="radio"
            name="phonetype" id="home" value="home">
                    <label class="radioButton" for="home">Home</label>

根据Dreamweaver,语法错误显然在这一行上,并且在编写代码时从早期出现错误,并在添加新代码时移动到更新的span类:

                    <span class="errorFeedback errorSpan phoneTypeError"        
            id="phonetypeError">Please choose an option</span>
                    <br />
                    <input type="submit" id="submit" name="submit">
                    </fieldset>

    </div>
    </form>
    </body>

当我尝试在网络浏览器中查看此页面时,它表明最后一行存在问题:

    </html>

我找错了,但似乎找到了任何明确的错误!

希望我不是傻瓜

3 个答案:

答案 0 :(得分:2)

您正在使用两次

<span class="errorFeedback errorSpan" id="password1Error">Password required</span>

删除其中的一个实例....

其次,您忘了关闭if的大括号。像这样关闭它

<?php
    if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) {
        unset($_SESSION['formAttempt']);
        print "Errors encountered<br />\n";
        foreach ($_SESSION['error'] as $error) {
            print $error . "<br />\n";
        } //end foreach
     }//<----- Add here
        ?>

答案 1 :(得分:1)

在php代码中添加最后一个括号。因为你使用if语句和foreach ..

<?php

     if() {
     //enter code here
       foreach() {
       //enter code here

       }
     }
?>

答案 2 :(得分:0)

您错过了IF语句的结束括号:

<?php
        if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) {
                unset($_SESSION['formAttempt']);
                print "Errors encountered<br />\n";
                foreach ($_SESSION['error'] as $error) {
                                print $error . "<br />\n";
                } //end foreach
        } // <-- MISSING
?>