Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php表单中的验证不起作用_Php - Fatal编程技术网

php表单中的验证不起作用

php表单中的验证不起作用,php,Php,嗨,我正在努力验证我的表格。我已经从w3school编译了代码,并检查了TA,没有发现任何错误。这是我的第一个php表单,我是一个真正的初学者。有人能帮我浏览一下我的php吗 <?php // define variables and set to empty values $nameErr = $emailErr = $genderErr = $websiteErr = ""; $name = $email = $gender = $comment = $

嗨,我正在努力验证我的表格。我已经从w3school编译了代码,并检查了TA,没有发现任何错误。这是我的第一个php表单,我是一个真正的初学者。有人能帮我浏览一下我的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>

if check的代码缺少“}”,什么不起作用?您收到了什么错误?没有发送错误表单但没有消息我已检查“}”。没有人失踪