php格式的验证不起作用

时间:2014-03-23 14:13:10

标签: php

您好我对表格的验证感到不满。我已经建立了w3school的代码,并通过它来检查tas,并且找不到任何错误。这是我的第一个php表单,我是一个真正的初学者。 someoe可以帮助我查看我的PHP。

    <?php
    // define variables and set to empty values
    $nameErr = $emailErr = $genderErr = $websiteErr = "";
    $name = $email = $gender = $comment = $website = "";

    if ($_SERVER["REQUEST_METHOD"] == "POST")
    {
    if (empty($_POST["name"]))
    {$nameErr = "Name is required";}
    else
    {$name = test_input($_POST["name"]);
     // check if name only contains letters and whitespace
     if (!preg_match("/^[a-zA-Z ]*$/",$name))
     {$nameErr = "Only letters and white space allowed";}
     }
     *
     *
     *
     *
     *
     function test_input($data)
     {
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
     }
     // Always set content-type when sending HTML email
     $headers = "MIME-Version: 1.0" . "\r\n";
     $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

     // More headers
    $headers .= 'From: <mpa@giz-zuerich.ch>' . "\r\n";
    //$headers .= 'Cc: myboss@example.com' . "\r\n";

    // send email
    mail($strEmpfaenger,$strSubject,$mitteilung,$headers);
    header('Location: http://www.giz-zuerich.ch/_private/sites/danke.html');
    ?>

我的HTML代码如下所示:

    <form action="../php/terminform.php" method="post">
       <dl>
    <dt><label for="name" >Name</label></dt>
    <dd><input type="text" name="name" value="">
        <span class="error"> *<?php echo $nameErr;?></span></dd>
      </dl>
     </form>

1 个答案:

答案 0 :(得分:0)

'}' if()的代码缺失