Jump to content

Recommended Posts

Hey All,

 

I need some help retrieving values from a form which i have created using an array.

 

below is the code i used to create the form:

 

<form action="test.php" method="post" name="form1" id="login" style="margin-top:0">        
<?php
$fieldCount = 20;
for($i = 0; $i < $fieldCount; $i++)
{
	?>
	<table width="100%" border="0" cellspacing="0" cellpadding="5" class="texts">
	<tr>
    <th width="10" scope="col">Round</th>
    <th width="10" scope="col">Date</th>
    <th width="10" scope="col">Time</th>
    <th width="10" scope="col">Opposition</th>
    <th width="10" scope="col">Bye</th>
    <th width="10" scope="col">Field</th>
  </tr>
  
  <tr>
  	<td><input name="drawRound[<?= $i ?>]" type="text" size="2" maxlength="4"></td>
        <td><input name="drawDate[<?= $i; ?>]" type="text" size="8" ></td>
        <td><input name="drawTime[<?= $i; ?>]" type="text" size="4" ></td>
        <td><input name="drawOpposition[<?= $i; ?>]" type="text" size="20"></td>
        <td><input name="bye[<?= $i; ?>]" type="checkbox" value="BYE"></td>
        <td><input name="drawField[<?= $i; ?>]" type="text" size="2"></td>
  </tr>  

</table>
<hr width="75%">  
<?php } ?>
        <table width="100%"  border="0" cellpadding="0" cellspacing="0">
                <tr align="center">
                  <td height="21" valign="bottom" align="center"><input name="imageField2" type="image" src="../Files/Buttons/submit.gif" alt="Submit & Continue" width="150" height="23" border="0"></td>
                </tr>
        </table>
<br />
</form>

 

As you can see i have made it so that the code repeats 20 times to make 20 lots of the same row of fields, except that the name of the object increases by one each time the code is repeated.

 

How would i extract those rows and turn them into variables to then be inserted into a database?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/73915-form-arrays/
Share on other sites

At first:

That code is wrong.

It should look like this:

<form action="test.php" method="post" name="form1" id="login" style="margin-top:0">        
<?php
$fieldCount = 20;
for($i = 0; $i < $fieldCount; $i++)
{
	?>
	<table width="100%" border="0" cellspacing="0" cellpadding="5" class="texts">
	<tr>
    <th width="10" scope="col">Round</th>
    <th width="10" scope="col">Date</th>
    <th width="10" scope="col">Time</th>
    <th width="10" scope="col">Opposition</th>
    <th width="10" scope="col">Bye</th>
    <th width="10" scope="col">Field</th>
  </tr>
  
  <tr>
  	<td><input name="drawRound[<? echo $i ?>]" type="text" size="2" maxlength="4"></td>
        <td><input name="drawDate[<? echo $i; ?>]" type="text" size="8" ></td>
        <td><input name="drawTime[<? echo $i; ?>]" type="text" size="4" ></td>
        <td><input name="drawOpposition[<? echo $i; ?>]" type="text" size="20"></td>
        <td><input name="bye[<? echo $i; ?>]" type="checkbox" value="BYE"></td>
        <td><input name="drawField[<? echo $i; ?>]" type="text" size="2"></td>
  </tr>  

</table>
<hr width="75%">  
<?php } ?>
        <table width="100%"  border="0" cellpadding="0" cellspacing="0">
                <tr align="center">
                  <td height="21" valign="bottom" align="center"><input name="imageField2" type="image" src="../Files/Buttons/submit.gif" alt="Submit & Continue" width="150" height="23" border="0"></td>
                </tr>
        </table>
<br />
</form>

 

And you can get them as this:

$_POST["drawRound"][0]

Just change variable name and array number.

Link to comment
https://forums.phpfreaks.com/topic/73915-form-arrays/#findComment-372996
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.