![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| Hi, I am just starting up with PHP (although I am trained in ColdFusion) and am having problems with the following code: $collist = "test1, test2, test3, test4"; $aColumns = explode(",",$collist); $aValues = array(); while (list($idx, $value) = each($aColumns)) { print("IDX: $idx; VALUE: $value; Field: ".$HTTP_POST_VARS[$value]."<br>"); } My main plan was to loop through a list of hardcoded columns passed to the function and retrieve the values from the posted form fields that match the column name. This might seem a little odd, but it fits in well with out application.# The problem is that even though form is being posted with the correct field names, the $HTTP_POST_VARS[$value] line is coming back with an empty string. I have tried: $HTTP_POST_VARS["$value"] $HTTP_POST_VARS[($value)] $HTTP_POST_VARS[$value] Can anyone tell me what I am doing wrong? Thanks very much Andy Hall. | |||
| Advertisements |
| | #2 | ||
| > Hi, > <snip> > > I have tried: > $HTTP_POST_VARS["$value"] > $HTTP_POST_VARS[($value)] > $HTTP_POST_VARS[$value] > > I have also now tried ${"HTTP_POST_VARS".$value} which I found on a PHP array help page, but to no avail. Any other ideas greatly appreciated... | |||
| | #3 | ||
| did u try $_POST[$value] On Mon, 11 Aug 2003 10:34:04 +0000 (UTC), "Andy Hall" <andy@jaar.co.uk> wrote: >> Hi, >> ><snip> >> >> I have tried: >> $HTTP_POST_VARS["$value"] >> $HTTP_POST_VARS[($value)] >> $HTTP_POST_VARS[$value] >> >> > >I have also now tried ${"HTTP_POST_VARS".$value} which I found on a PHP >array help page, but to no avail. > >Any other ideas greatly appreciated... > > | |||
| | #4 | ||
| Thats seems to have worked for the first array element, but the rest are blank. Still, I have something to pursue now - thanks for your help. Andy. "Warstar" <warstar@NSA.com> wrote in message news:hjsejv8kf3vp7cf7f76ttq0e3ab83ch0ti@4ax.com... > did u try > $_POST[$value] > > > On Mon, 11 Aug 2003 10:34:04 +0000 (UTC), "Andy Hall" > <andy@jaar.co.uk> wrote: > > >> Hi, > >> > ><snip> > >> > >> I have tried: > >> $HTTP_POST_VARS["$value"] > >> $HTTP_POST_VARS[($value)] > >> $HTTP_POST_VARS[$value] > >> > >> > > > >I have also now tried ${"HTTP_POST_VARS".$value} which I found on a PHP > >array help page, but to no avail. > > > >Any other ideas greatly appreciated... > > > > > | |||
| | #5 | ||
| if your on PHP ver 4.1.0+ I'd use $_POST["value"]; I believe HTTP_POST_VARS is being deprecated. Call your array item variable something different to $value. Your asking for a field called test1, test2 etc from the form by calling them the same, which doesn't exist, hence a blank field.......I think! :-) array item variable name doesn't matter what it is. Regards Paul -- Posted via http://dbforums.com | |||
| | #6 | ||
| thanks for the help. It is now working for the first array element but no further. The code: $collist = "test1, test2, test3, test4"; $aColumns = explode(",",$collist); $aValues = array(); while (list($fieldidx, $fieldv) = each($aColumns)) { print("IDX: $fieldidx; VALUE: $fieldv; Field: " . $_POST[$fieldv] . "<br>"); } is outputting: IDX: 0; VALUE: test4; Field: 4 IDX: 1; VALUE: test3; Field: IDX: 2; VALUE: test2; Field: IDX: 3; VALUE: test1; Field: 4 is the correct value for the test4 field but the others are blank. If I switch the order of collist the first one always is correct but the rest are blank. Is there something else stupid I am doing. I have looked on the net but I am under pressure not to spend to long on this as I could always hardcode my queries. but, being a fool, I want to create reusable code!! Thanks for your help Andy. "pprince" <member29867@dbforums.com> wrote in message news:3224167.1060599668@dbforums.com... > > if your on PHP ver 4.1.0+ I'd use $_POST["value"]; > > I believe HTTP_POST_VARS is being deprecated. > > Call your array item variable something different to $value. Your asking > for a field called test1, test2 etc from the form by calling them the > same, which doesn't exist, hence a blank field.......I think! :-) > array item variable name doesn't matter what it is. > > Regards > > Paul > > -- > Posted via http://dbforums.com | |||
| | #7 | ||
| whats the form code ? your asking for the values of form fields test1, test2, test3 & test4, do these form fields exist? what type? if they're checkboxes for example they won't get posted. -- Posted via http://dbforums.com | |||
| | #8 | ||
| -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Whilst lounging around on Mon, 11 Aug 2003 14:08:12 +0000, pprince <member29867@dbforums.com> amazingly managed to produce the following with their Etch-A-Sketch: > if they're checkboxes for example they won't get posted. Huh? why not? I happily use checkboxes on forms and receive data with them. Mighty handy they are too! =) Regards, Ian -----BEGIN PGP SIGNATURE----- Version: PGP 8.0 iQA/AwUBPzeroWfqtj251CDhEQL3WwCg9ZaMGg1jzU7mAu+sfAgwEm duKhwAoP3X MsMb16h3MmtGOxqH1wD1xrCi =kwZ8 -----END PGP SIGNATURE----- -- Ian.H [Design & Development] digiServ Network - Web solutions www.digiserv.net | irc.digiserv.net | forum.digiserv.net Programming, Web design, development & hosting. | |||
| | #9 | ||
| Thanks for the idea, but I am aware that a unchecked checkbox does not get posted. I am posting a form with the 4 text fields test1, test2, test3, test4. I have looped through _POST and outputted all the fields and values, but when it comes to dynamically generating the variable name in my loop everything is falling flat on its face. Thanks for the ideas though... "Ian.H [dS]" <ian@WINDOZEdigiserv.net> wrote in message news:mrafjvc7n0i009hnbir3entrujmfi41s68@4ax.com... > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Whilst lounging around on Mon, 11 Aug 2003 14:08:12 +0000, pprince > <member29867@dbforums.com> amazingly managed to produce the following > with their Etch-A-Sketch: > > > if they're checkboxes for example they won't get posted. > > > Huh? why not? I happily use checkboxes on forms and receive data with > them. Mighty handy they are too! =) > > > > Regards, > > Ian > > -----BEGIN PGP SIGNATURE----- > Version: PGP 8.0 > > iQA/AwUBPzeroWfqtj251CDhEQL3WwCg9ZaMGg1jzU7mAu+sfAgwEm duKhwAoP3X > MsMb16h3MmtGOxqH1wD1xrCi > =kwZ8 > -----END PGP SIGNATURE----- > > -- > Ian.H [Design & Development] > digiServ Network - Web solutions > www.digiserv.net | irc.digiserv.net | forum.digiserv.net > Programming, Web design, development & hosting. | |||
| | #10 | ||
| Man its so obvious sometimes!!! you need to trim the leading space in $collist for test2, 3 & 4. I've just added a trim to the $_POST expression. Does work as I've tested it. Thats why test1 was ok and not for the other 3. $collist = "test1, test2, test3, test4"; $aColumns = explode(",",$collist); $aValues = array(); while (list($fieldidx, $fieldv) = each($aColumns)) { print("IDX: $fieldidx; VALUE: $fieldv; Field: " . $_POST[trim($fieldv)] . "<br>"); } Regards -- Posted via http://dbforums.com | |||
| Featured Websites | ||||
|
![]() |
| Tags: dynamic, variables |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Shopping Cart Software | Barrie Tingle | PHP | 0 | 07-01-2007 3:19 PM |
| Dynamic Creation of Rows | Mr. Clean | PHP | 4 | 07-01-2007 3:18 PM |
| Dynamic Solutions for Dynamic URLs on Data Driven Sites | hirenseo | HTML | 4 | 07-31-2006 12:27 AM |
| Dynamic Web Design:: PHP Vs ASP: | colin | Website Coding | 0 | 07-30-2006 5:52 PM |
| Featured Websites | ||||
|