473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

For loop to retreive form data - Probably simple fix

Hi all.

I'm a noobie, so please bear with me !

I have written an html form with the following code..
Expand|Select|Wrap|Line Numbers
  1. <select name="player1"> options.... </select>
  2. <select name="player2"> options.... </select>
  3. <select name="player3"> options.... </select>
  4. and so on.
  5.  
I need to write the values of each select tag into an XML file BUT for the purpose of this exercise, I would like to be able to simply write the variable out using a 'for' function to loop through each.

Heres what I have, but it's not working (I didn't really expect it to as I think I'm approaching the problem from the wrong direction).
Expand|Select|Wrap|Line Numbers
  1. for ($i=1; $i<=14; $i++)
  2.   {
  3.   $text = '$_POST["player' . $i . '"]';
  4.   echo  $text . <br />;
  5.   }
  6.  
If anyone knows of a way I can do this successfully then it would be greatly appreciated.
Thanks,
Phil
May 16 '11 #1

✓ answered by Dormilich

single quoted strings are not parsed for variables, i.e line 3 would result in the string literal '$_POST["player1"]' not the POST superglobal.

since you can’t be sure if all posted variables exist in the for() loop, you need to use an existance check before accessing the elements.
Expand|Select|Wrap|Line Numbers
  1. $index = "player" . $i;
  2. if (isset($_POST[$index]))
  3. {
  4.     echo $_POST[$index], '<br>';
  5. }

4 1685
Dormilich
8,658 Expert Mod 8TB
single quoted strings are not parsed for variables, i.e line 3 would result in the string literal '$_POST["player1"]' not the POST superglobal.

since you can’t be sure if all posted variables exist in the for() loop, you need to use an existance check before accessing the elements.
Expand|Select|Wrap|Line Numbers
  1. $index = "player" . $i;
  2. if (isset($_POST[$index]))
  3. {
  4.     echo $_POST[$index], '<br>';
  5. }
May 17 '11 #2
Vielen danke Dormilich.

Ich habe mein Problem gelost.

Ich benotige nicht wenn Aussage, wahrend ich weiss, wieviele Variablen dort sind.

:-)
May 17 '11 #3
Dormilich
8,658 Expert Mod 8TB
Ich benotige nicht wenn Aussage, wahrend ich weiss, wieviele Variablen dort sind.
this would imply that your script would only ever called from that page, which is not guaranteed.
May 18 '11 #4
That is correct. I only need to run this on 1 page.

Thanks again for your help.
May 18 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt | last post by:
I have a html form, and I want to transform html form data to xml string. Given XSD (xml schema), how to transform the form data to xml string?
2
by: Citoyen du Monde | last post by:
Trying to get some ideas on a simple javascript project (to teach myself the language). I want to develop a client-side vocabulary practice application that would allow users to enter their own...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
3
by: NextOne | last post by:
Hi ! Is it possible to send an AJAX XMLHttpRequest using prototype.js API for a multipart/form-data ? I already done parsing form parameters and sending GET/POST request, but does this work...
1
by: LD | last post by:
Hi, I'm pulling my hair out!! My problem is, I need to automatically upload a zip file along with 3 other pieces of text data to a web server and wait for it's xml response. Basically a...
3
by: Jon Petrak | last post by:
I'm sorry if this is the wrong newsgroup, but the ASP ones seem to be devoid of any talk about ASP (and rather filled with spam). I have a very simple form here that loops back into upon...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
2
by: eselk2003 | last post by:
I have a Windows application that uses the Windows Internet (wininet) API to post a few lines of text to an ASP.NET page that I'm writing. I know how to process form data in ASP.NET, but not sure...
1
by: Spencer Killen | last post by:
In my website i have forms that are submitted into the URL and then converted into javascript on the next page, i wish to have sort of like a survey on the first page and then she the results of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.