RE: [PHP] Getting at $_POST values using a loop
| From: | Ford, Mike [LSS] | Date: | Mon, 23 Jun 2003 12:46:40 +0000 |
| Subject: | RE: [PHP] Getting at $_POST values using a loop | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-152489@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Dave Alger [mailto:news@alger2000.freeserve.co.uk]
> Sent: 23 June 2003 05:12
>
> This one is causing me a few headaches. How should I be doing this?
>
> On my previous page I've created a series of fields using a
> loop so that a
> field is created like this:
>
> echo "<hr>$fieldname:<input name='Field$n'
> maxlength='25'>";
>
> On my next page then I've got to try to read these values. I
> could do this
> as $_POST['Field0'], $_POST['Field1'] etc but a loop is what
> is required.
>
> I've tried getting at the value by:
>
> $a=$_POST['Field$n'];
>
> and
>
> $nb='$'."_POST['Field".$n."']";
> $a=$$nb;
>
> And neither works. How should I be doing it?
Well, ideally I'd go with the array-based rewrite already offered -- but if you must stick with
fields named Field1, Field2 etc., use one of these:
$a = $_POST["Field$n"];
$a = $_POST['Field'.$n];
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211