0

这是html表单代码:注册

    <body>
    <img src="Images/zombie 5k TM AP2.png" width="1020" height="1020" usemap="#Map" border="0" />
    <div class="TEdit" id="Edit1" style="position: absolute; left: 335px; top: 267px; width: 527px; height: 766px;">
    <form method="post" action="send_form.php">
    <fieldset>
            <strong>Runner Registration</strong>
    <div class="fields">
                <p class="row">
                    <label for="last-name">Last Name:</label>
                    <input type="text" id="last-name" name="last-name" class="field-large" />
                </p>
                <p>
                    <label for="first-name">First Name:</label>
                    <input type="text" id="First-name" name="first-name" class="field-large" />
                </p>
                <p>
                    <label for="initial">Initial:</label>
                    <input type="text" id="initial" name="inital" class="field-small" />
                </p>
                <p>
                    <label for="address">Address:</label>
                    <input type="text" id="address" name="address" class="field-large" />
                </p>
                <p>
                    <label for="city">City:</label>
                    <input type="text" id="city" name="city" class="field-small" />
        <div class="row">
                        <label for="state">State:</label>
                        <select id="state" name="state">
                            <option value="AL">Alabama</option>
                            <option value="AK">Alaska</option>
                            <option value="CA">California</option>
                            <option value="CO">Colorado</option>
                        </select>
        </div>
                    <div class="row">
                    <label for="zip">Zip:</label>
                    <input type="text" id="zip" name="zip" class="field-small" />
                    </div>
                <p>
                    <label for="phone">Phone:</label>
                    <input type="text" id="phone" name="phone" class="field-large" />
            </p>
            <p>
                    <label for="email">Email:</label>
                    <input type="text" id="email" name="email" class="field-large" />
            </p>
        <p>
      <label for="econtact">Emergency Contact:</label>
              <input type="text" id="econtact" name="econtact" class="field-medium" />
              <label for="ephone">Phone:</label>
              <input type="text" id="ephone" name="ephone" class="field-larcg" />
            </p>
    </div>
    <div class="fields">
                <p class="row">
                    <label for="male">Male:</label>
                    <input type="checkbox" id="male" name="male" class="checkboxes"/>
                    <label for="female">Female:</label>
                    <input type="checkbox" id="female" name="female" class="checkboxes" />
                </p>
            <p>
                    <label for="age">Age:</label>
                    <input type="text" id="age" name="age" class="field-small" />
          </p>
          <p>
              <label for="small">Small:</label>
              <input type="checkbox" id="small" name="sise[]" value="Small"     class="checkboxes"/>
              <label for="medium">Medium:</label>
              <input type="checkbox" id="medium" name="size[]" value="Medium" class="checkboxes" />
              <label for="large">Large:</label>
              <input type="checkbox" id="large" name="size[]" value="Large" class="checkboxes"/>
              <label for="xlarge">xlarge:</label>
              <input type="checkbox" id="xlarge" name="size[]" value="X-Large"     class="checkboxes" />
              <label for="xxlarge">xxlarge:</label>
              <input type="checkbox" id="xxlarge" name="size[]" value="XX-Large" class="checkboxes" />
          </p>
          <p align="center"><strong>Free T-Shirt: Guaranteed to all pre-registrants          </strong><br>
      Registrations after 8/01/2014 will receive a T-shirt as long as supplies last </p>
          <p align="center">
        Entry Fee: $35 until 7/31/2014 - $40 after<br />
        Entry Fee non-refundable and on-transferable<br />
        Make checks payable to:<br /><br />

        <strong>Ironton Fire Department Women's Auxiliary<br />
        601 Mattson Ave<br />
        Ironton, Mn. 56455
        </strong></p>
        <p align="center">
      <input type="submit" align="middle" />
      </p>
    </div>
    </fieldset>
     </form>
     </div>
    <map name="Map" id="Map">
       <area shape="rect" coords="158,276,290,318" href="index.html" alt="Home" />
       <area shape="rect" coords="157,318,289,359" href="Register.html" alt="Register" />
       <area shape="rect" coords="159,360,289,405" href="Sponsors.html" alt="Sponsors" />
       <area shape="rect" coords="159,406,290,453" href="Gallery.html" alt="Gallery" />
    </map>


    </body>
    </html>

这是php代码

        <?php
        if(isset($_POST['email'])) {

            // EDIT THE 2 LINES BELOW AS REQUIRED
            $email_to = "tlavalle@gmail.com";
          $email_subject = "Runner Registration";


           function died($error) {
                // your error code can go here
                echo "We are very sorry, but there were error(s) found with the form you     submitted. ";
                echo "These errors appear below.<br /><br />";
                echo $error."<br /><br />";
                echo "Please go back and fix these errors.<br /><br />";
                die();
            }

            if( isset($_POST['size']) && is_array($_POST['sizze']) ) {
            foreach($_POST['size'] as $size) {
            }

            // validation expected data exists
            if(!isset($_POST['last-name']) ||
                !isset($_POST['first-name']) ||
                !isset($_POST['inital']) ||
                !isset($_POST['address']) ||
                !isset($_POST['city']) ||
            isset($_POST['state']) ||
                !isset($_POST['zip']) ||
                !isset($_POST['phone']) ||
            !isset($_POST['email']) ||
                !isset($_POST['econtact']) ||
                !isset($_POST['ephone']) ||
            !isset($_POST['age'])) {
                died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

            $first_name = $_POST['first-name']; // required
            $last_name = $_POST['last-name']; // required
            $inital = $_POST['initial']; // required
            $address = $_POST['address']; // required
            $city = $_POST['city']; // required
            $state = $_POST['state']; // required
            $zip = $_POST['zip']; // required
            $phone = $_POST['phone']; // required
            $email = $_POST['email']; // required
            $econtact = $_POST['econtact']; // required
            $ephone = $_POST['ephone']; // required
            $age = $_POST['age']; // required
            $size = $_POST['size']; // required


            $error_message = "";
            $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

          if(!preg_match($email_exp,$email_from)) {
            $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
      }
            $string_exp = "/^[A-Za-z .'-]+$/";
          if(!preg_match($string_exp,$first_name)) {
            $error_message .= 'The First Name you entered does not appear to be valid.<br />';
          }
          if(!preg_match($string_exp,$last_name)) {
            $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      }

          if(strlen($error_message) > 0) {
            died($error_message);
          }
            $email_message = "Form details below.\n\n";

            function clean_string($string) {
              $bad = array("content-type","bcc:","to:","cc:","href");
              return str_replace($bad,"",$string);
            }

            $email_message .= "First Name: ".clean_string($first_name)."\n";
            $email_message .= "Last Name: ".clean_string($last_name)."\n";
            $email_message .= "Initial: ".clean_string($initial)."\n";
        $email_message .= "Address: ".clean_string($address)."\n";
            $email_message .= "City: ".clean_string($city)."\n";
        $email_message .= "State: ".clean_string($state)."\n";
        $email_message .= "Zip: ".clean_string($zip)."\n";
        $email_message .= "Phone: ".clean_string($phone)."\n";
        $email_message .= "Email: ".clean_string($email)."\n";
        $email_message .= "Emergency Contact: ".clean_string($econtact)."\n";
        $email_message .= "Emergency Phone: ".clean_string($ephone)."\n";
        $email_message .= "Age: ".clean_string($age)."\n";

        // create email headers
        $headers = 'From: '.$email_from."\r\n".
        'Reply-To: '.$email_from."\r\n" .
        'X-Mailer: PHP/' . phpversion();
        @mail($email_to, $email_subject, $email_message, $headers);  
        ?>
        <!-- include your own success html here -->

        Thank you for contacting us. We will be in touch with you very soon.

        <?php
        }
        ?>

我在 php 代码的最后一行收到错误消息。另外,当我尝试测试它时,它只是将我放到 php 文件的源代码中,可以看看这个并给我指出我出错的地方以及我可以改进的地方吗?

4

1 回答 1

2

在第 19 行,您有一个未关闭/未执行任何操作的 foreach 循环。

        if( isset($_POST['size']) && is_array($_POST['sizze']) ) {
            foreach($_POST['size'] as $size) {
        }
于 2013-11-07T17:23:55.100 回答