验证简介中断脚本

时间:2011-11-11 01:22:45

标签: php validation

使用以下脚本将信息发送到flatfile,直到引入验证为止。在第23行的括号中获得Parse错误。 破损的可能原因是什么?

<?php
    // we must never forget to start the session
    session_start();
    ?>
    <html>
    <head>
    <title>Form to Flat File</title>
    </head>
    <body>
    <?php
    $vname = $_GET["visitor"];
    $vemail = $_GET["visitormail"];
    $vphone = $_GET["visitorphone"];
    $ip = $_SERVER['REMOTE_ADDR'];
    $httpref = $_SERVER['HTTP_REFERER'];
    $httpagent = $_SERVER['HTTP_USER_AGENT'];
    $todayis = date("l, F j, Y, g:i a") ;

    // VALIDATION INTRODUCTION - THESE ARE THE FORM FIELDS THAT WE REQUIRED THE VISITOR TO FILL IN  
        if(empty($vname) 
        || empty($vemail) 
        || empty($vphone) 
        {      //Parse error: parse error in C:\wamp\www\Poll\DRBPoll\RaffleInfo.php on line 23
        echo "<h2>Go Back and fill in all fields  </h2>\n";
        echo '<a href="javascript:history.go(-1)"><h3>Go Back to the Raffle Form</h3></a><br />';    /*GO BACK BUTTON*/
        die ("Use the Go Back to Raffle Form button !! ");
        }
        if(!$vemail == "" && (!strstr($vemail,"@") || !strstr($vemail,"."))) 
        {
        echo "<h2>Go Back and enter a valid E-mail Address</h2>\n";
        echo '<a href="javascript:history.go(-1)"><h3>Go Back to the Raffle Form</h3></a><br />';    /*GO BACK BUTTON*/
        die ("Use the Go Back to Raffle Form button !!");   
        }

    // THANK YOU MESSAGE IS WORKING

    print("<b>Thank You!</b><br />Your information will be entered once into the raffle!");
    $out = fopen("savedinfo.php", "a");
    if (!$out) {
    print("Could not add detail to Raffle file! Please contact the Webmaster");
    exit;
    }
    //OUTPUTS TO THE FLATFILE IS WORKING
    fputs ($out, "\n");
    fwrite($out,"$todayis [IST], $vname, $vemail, $vphone, $ip, $httpref, $httpagent.");
    fclose($out);
    ?>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您忘记关闭在if旁边打开的括号。

替换:

    if(empty($vname)
    || empty($vemail)
    || empty($vphone)

使用:

    if(empty($vname)
    || empty($vemail)
    || empty($vphone))