Chris1981 Posted October 19, 2007 Share Posted October 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73915-form-arrays/ Share on other sites More sharing options...
enoyhs Posted October 19, 2007 Share Posted October 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73915-form-arrays/#findComment-372996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.