bluegrass Posted August 31, 2008 Share Posted August 31, 2008 Hi, I've been working on a simple project to get myself into PHP which is basically a prediction league for soccer results. My problem is that I have a form for adding predictions, which has two input fields for the score value, but I have multiple instances of this in one form. I'm iterating through my database and outputting all of the matches in the database, and on each iteration doing the following echo " <td>".$team1."</td> <td><input name=\"score1\" size=\"2\"></td> <td>-</td> <td><input name=\"score2\" size=\"2\"></td> <td>".$team2."</td> "; My problem is when I process this form and do $_POST['score1'] for example, I obviously just get the last score1 value entered. I'm looking for a way to pass all of them to my form processor. Is this possible whilst using the same input names or do they have to be unique? The values also correspond to a unique ID as well, which I was experimenting with using as a hidden value, but I can't find a way to reference "id#1.score1" i.e. score1 corresponding to id#1. Any help on how to do this would be greatly appreciated (or indeed a suggestion for a better way to achieve this) Thanks in advance Link to comment https://forums.phpfreaks.com/topic/122129-php-forms-help/ Share on other sites More sharing options...
kratsg Posted August 31, 2008 Share Posted August 31, 2008 Use as an array instead: echo " <td>$team1</td> <td><input name='score1[]' size='2'></td> <td>-</td> <td><input name='score2[]' size='2'></td> <td>$team2</td> "; So the array will look like: Array([0]=>SCORE1,[1]=>SCORE1, etc...) where SCORE1 = values. If you want it to put it in a format such as [$TEAM1]=>SCORE1, then use this code: echo " <td>$team1</td> <td><input name='score1[$team1]' size='2'></td> <td>-</td> <td><input name='score2[$team2]' size='2'></td> <td>$team2</td> "; Link to comment https://forums.phpfreaks.com/topic/122129-php-forms-help/#findComment-630560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.