Form Loop Error

Posted by JM4 on Stack Overflow See other posts from Stack Overflow or by JM4
Published on 2010-05-18T00:51:43Z Indexed on 2010/05/18 1:00 UTC
Read the original article Hit count: 372

Filed under:

I have a form which loops if the value indicated is less than or equal the number of 'enrollee's needed. The while loop works perfectly with one exception, I use DOB fields which ALSO use FOR loops to display their values. If I remove the DOB fields, the form loop works fine, when left in, it errors out. Any ideas?

<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>

© Stack Overflow or respective owner

Related posts about php