表格循环错误

时间:2010-05-18 00:51:44

标签: php

如果指示的值小于或等于'enrollee'所需的数量,我有一个循环的表单。 while循环完美地有一个例外,我使用DOB字段,它们也使用FOR循环来显示它们的值。如果我删除DOB字段,表单循环工作正常,当放入时,它会出错。有什么想法吗?

<form id="Enroll_Form"  action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="Enroll_Form" >

<?php 
$i=1;
while ($i <= ($_SESSION['Num_Members'])): {?>

    <table class="demoTable">
    <tr>
      <td>First Name: </td>
        <td><input type="text" name="F1FirstName" value="<?php echo $fields['F1FirstName']; ?>" /></td>
    </tr>
    <tr>
      <td>Middle Initial: </td>
        <td><input type="text" name="F1MI" size="2" maxlength="1" value="<?php echo $fields['F1MI']; ?>" /></td>
    </tr>
    <tr>
      <td>Last Name: </td>
        <td><input type="text" name="F1LastName" value="<?php echo $fields['F1LastName']; ?>" /></td>
    </tr>
    <tr>
      <td>Federation No: </td>
        <td><input type="text" name="F1FedNum" maxlength="10" value="<?php echo $fields['F1FedNum']; ?>" /></td>
    </tr>
    <tr>
      <td>SSN: </td>
        <td><input type="text" name="F1SSN1" size="3" maxlength="3" value="<?php echo $fields['F1SSN1']; ?>" /> - 
        <input type="text" name="F1SSN2" size="2" maxlength="2" value="<?php echo $fields['F1SSN2']; ?>" /> - 
        <input type="text" name="F1SSN3" size="4" maxlength="4" value="<?php echo $fields['F1SSN3']; ?>" />
        </td>
    </tr>
    <tr>
      <td>Date of Birth</td>
        <td>
        <select name="F1DOB1">
            <option value="">Month</option> 
            <?php
                for ($i=1; $i<=12; $i++)
          {
            echo "<option value='$i'";
            if ($fields["F1DOB1"] == $i)
              echo " selected";
            echo ">$i</option>";
          }
          ?>            
        </select> / 
        <select name="F1DOB2">
            <option value="">Day</option>
            <?php
                for ($i=1; $i<=31; $i++)
          {
            echo "<option value='$i'";
            if ($fields["F1DOB2"] == $i)
              echo " selected";
            echo ">$i</option>";
          }
          ?>
        </select> / 
        <select name="F1DOB3">
            <option value="">Year</option>
            <?php
                for ($i=date('Y'); $i>=1900; $i--)
          {
            echo "<option value='$i'";
            if ($fields["F1DOB3"] == $i)
              echo " selected";
            echo ">$i</option>";
          }
          ?>
        </select>
        </td>
    </tr>
    <tr>
      <td>Address: </td>
        <td><input type="text" name="F1Address" value="<?php echo $fields['F1Address']; ?>" /></td>
    </tr>
    <tr>
      <td>City: </td>
        <td><input type="text" name="F1City" value="<?php echo $fields['F1City']; ?>" /></td>
    </tr>
    <tr>
      <td>State: </td>
        <td><select name="F1State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td> 
    </tr>
    <tr>
      <td>Zip Code: </td>
        <td><input type="text" name="F1Zip" size="6" maxlength="5" value="<?php echo $fields['F1Zip']; ?>" /></td>
    </tr>
    <tr>
      <td>Contact Telephone No: </td>
        <td>( <input type="text" name="F1Phone1" size="3" maxlength="3" value="<?php echo $fields['F1Phone1']; ?>" /> ) 
        <input type="text" name="F1Phone2" size="3" maxlength="3" value="<?php echo $fields['F1Phone2']; ?>" /> - 
        <input type="text" name="F1Phone3" size="4" maxlength="4" value="<?php echo $fields['F1Phone3']; ?>" />
        </td>
    </tr>
    <tr>
      <td>Email:</td>
        <td><input type="text" name="F1Email" value="<?php echo $fields['F1Email']; ?>" /></td>
    </tr>    
    </table>
<br />
<?php } $i++; endwhile; ?>

<div align="right"><input class="enrbutton" type="submit" name="submit" value="Continue" /></div>
</form>

1 个答案:

答案 0 :(得分:3)

您在$i循环以及所有while循环中使用for。您需要将其更改为其他内容。

这可能会给你带来一些问题(更不用说它非常难以理解)