<HTML>
Thank you, Michael. I'll give those hints a try.<BR>
<BR>
<BR>
Maggie<BR>
VK3CFI <BR>
<BR>
<span style="font-weight: bold;">On Sat Oct 30 17:10 , Michael Greenhill <mi@whsc.vic.edu.au> sent:<BR>
<BR>
</mi@whsc.vic.edu.au></span><blockquote style="border-left: 2px solid rgb(245, 245, 245); margin-left: 5px; margin-right: 0px; padding-left: 5px; padding-right: 0px;">I always prefer to use $_REQUEST[value] instead of $_POST[]. Also, don't forget to wrap your $_REQUEST or $_POST in htmlspecialchars - eg:&nbsp;<div><BR>
</div><div>htmlspecialchars($_POST['languages']);</div><div><BR>


</div><div><BR>
</div><div><br clear="all">Regards,<BR>
Michael Greenhill<BR>
<BR>
Please think of the environment before printing off this email or any attachments.<BR>

<BR>
<BR>
<div class="gmail_quote">On Sat, Oct 30, 2010 at 4:41 PM, Margaret King Iaquinto <span dir="ltr">&lt;<a href="javascript:top.opencompose('iaquinto@ozemail.com.au','','','')">iaquinto@ozemail.com.au</a>&gt;</span> wrote:<BR>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">


My code didn't show up -- for the HTML, that is. Apologies<BR>

<BR>

So here it is , I hope.<div class="im"><BR>

<BR>

"<p><input name="languages[]"  ="" type="text">Add a language</p>"<BR>

"<p><input name="languages[]"  ="" type="text"> Add a language</p>"<BR>

"<p><input name="languages[]"  ="" type="text"> Add a language</p>"<BR>

"<p><input name="languages[]"  ="" type="text"> Add a language</p>"<BR>

<BR>
</div>
I used the name of the input box as languages[ ] -- to indicate an array.<BR>

<BR>

When sent to the server, the php used this line of code to store the contents of the array:<BR>

<BR>

$languages = $_POST['languages'];<BR>

<BR>

In the case above, I have shown 4 data items to be stored in the area. This is a fixed number. Sure, the user can enter fewer than the 4 displayed. No problems.<BR>

<BR>

What I want to learn is: how to allow the user to choose his own number of data items to enter. He may have 5 or 10, whatever. But that would mean my HTML form is unusually (and foolishly) long. Even then, I may not be able to accommodate the huge number of data items for this array.<BR>



<BR>

So, my user hits the form and it can instruct the user this way : "Enter the names of the programming languages you know. Type in a -1 when finished." Or something to that effect.<BR>

<BR>

The user will then enter 5 or 10 languages. The -1 is a signal that the data entry is finished. It doesn't need to be a -1 but something that triggers the end of the data entry. Like "Press hash to end the message."<BR>



<BR>

Thank you for the prompt reply!<BR>

<BR>

Maggie<BR>

VK3CFI <BR>

<BR>

<span style="font-weight: bold;">On Sat Oct 30 13:03 , Kevork Krozian  sent:<BR>

<BR>

</span><blockquote style="border-left: 2px solid rgb(245, 245, 245); margin-left: 5px; margin-right: 0px; padding-left: 5px; padding-right: 0px;"><div class="im">Hi Maggie,<BR>


<BR>


 <BR>


I need more information.<BR>


 I am a little thrown by the fact you have PHP code within the html part of the form - languages[].<BR>


You could call them lang1, lang2, lang3, lang4 and when received in the page at the server to process, you can go to the end of your array and add each of the lang1, lang2, lang3, lang4 to it as follows:<BR>


<BR>


     $languages[] = $POST['lang1']; // add one more item to array $languages<BR>


     $languages[] = $POST['lang2']; // add one more item to array $languages<BR>


     $languages[] = $POST['lang3']; // add one more item to array $languages<BR>


     $languages[] = $POST['lang3']; // add one more item to array $languages<BR>


<BR>


However, if you go back to the form and submit again, the $languages[] array is no longer "alive" unless saved to a file to read from. Do I make sense ? You can keep it alive by keeping it as a session variable but it has to be passed back and forth to be alive in that session. You need to save it before the session ends otherwise it is gone. What is a session ? It is the time a browser window is open forwards, backwards etc until closed where the session ends.   <BR>




<BR>


If I can get a grasp of what you wish to do it would be easier to see the best way to go.<BR>


What I observe here is you wish to collect individual elements of an array via fields in a form restricted to 4 fields. This is kind of ok I guess but what is the design aim , to collect input to fill an array 1? 2 ? 3 ? 4? how many at a time ?<BR>




 Remember with PHP you have a client filling a form potentially in Lebanon and a server receiving the form contents to process it in Armenia. Therefore the application environment of VB is not a reasonable analogy because with VB you are using the form and processing at the same time in the one loop. Does that make sense ?<BR>




 It makes sense to collect data one "row" , "record" at a time and add to an array. You keep doing this for as long as you want, but need to save to a file to keep the data. Having a sentinel doesn't make sense as the cessation of form filling is the end of your input process.<BR>




 I don't wish to sound judgmental but the client /server concept is the point I am trying to explain. <BR>


Fill form -&gt; send to server -&gt; process data. If you fill form again repeat the previous loop having saved the data before leaving the processing . No need for a sentinel. <BR>


<BR>


I hope I have made some sense here<BR>


If not please tell me.<BR>


<BR>


Take Care<BR>


Kevork<BR>


<BR>


-----Original Message-----<BR>
</div><div class="im">

From: <a>php-bounces@edulists.com.au</a> [<a>php-bounces@edulists.com.au</a>','','','')"&gt;<a>php-bounces@edulists.com.au</a>] On Behalf Of Margaret Iaquinto<BR>


Sent: Saturday, 30 October 2010 3:41 PM<BR>


To: <a>php@edulists.com.au</a><BR>


Subject: [php] arrays and loops<BR>


<BR>


  I can gather data into an array by using a form. I can spill the <BR>


contents of that array by using a loop.<BR>


<BR>


In the code snippet below, the user enters the name of a programming <BR>


language.<BR>


<BR>


snippet from the form:<BR>


<BR>
</div>

p&gt;<input name="languages[]" type="text">Add a language<p></p><BR>


<p><input name="languages[]" type="text"> Add a language</p><BR>


<p><input name="languages[]" type="text"> Add a language</p><BR>


<p><input name="languages[]" type="text"> Add a language</p><div class="im"><BR>


<BR>


The php code snippet looks like this:<BR>


<BR>


echo "Display the data  -  using a REPEAT UNTIL loop";<BR>


echo "<BR>
</div><div class="im">
";<BR>


$position = 0;<BR>


do {<BR>


     echo "$languages[$position]";<BR>


     $position += 1;<BR>


     echo "<BR>
</div><div class="im">
";<BR>


}<BR>


while ($position &lt; count($languages));<BR>


<BR>


And the code works.<BR>


<BR>


The form limits the number of languages to four, in the code above.<BR>


<BR>


Is there a way to use a loop or some kind of syntax to ask the user to <BR>


keep entering data until a sentinel is entered?<BR>


In VB, I can use an InputBox within a loop. When the user types in, say <BR>


-1, this ends the loop and the array stops being filled.<BR>


<BR>


But how do I do that in PHP?<BR>


<BR>


Thanks<BR>


<BR>


Maggie<BR>


_______________________________________________<BR>


<a href="http://parse.pl?redirect=http://www.edulists.com.au" target="_blank"><span style="color: red;">http://www.edulists.com.au</span></a> - FAQ, resources, subscribe, unsubscribe<BR>


PHP Mailing List kindly supported by<BR>


<a href="http://parse.pl?redirect=http://www.vcaa.vic.edu.au" target="_blank"><span style="color: red;">http://www.vcaa.vic.edu.au</span></a> - Victorian Curriculum and Assessment Authority and<BR>


<a href="http://parse.pl?redirect=http://www.vitta.org.au" target="_blank"><span style="color: red;">http://www.vitta.org.au</span></a>  - VITTA Victorian Information Technology Teachers Association Inc<BR>


<BR>


_______________________________________________<BR>


<a href="http://parse.pl?redirect=http://www.edulists.com.au" target="_blank"><span style="color: red;">http://www.edulists.com.au</span></a> - FAQ, resources, subscribe, unsubscribe<BR>


PHP Mailing List kindly supported by<BR>


<a href="http://parse.pl?redirect=http://www.vcaa.vic.edu.au" target="_blank"><span style="color: red;">http://www.vcaa.vic.edu.au</span></a> - Victorian Curriculum and Assessment Authority and<BR>


<a href="http://parse.pl?redirect=http://www.vitta.org.au" target="_blank"><span style="color: red;">http://www.vitta.org.au</span></a>  - VITTA Victorian Information Technology Teachers Association Inc<BR>
</div>

)<BR>


</blockquote>
<BR>
<BR>
_______________________________________________<BR>

<a href="http://www.edulists.com.au" target="_blank">http://www.edulists.com.au</a> - FAQ, resources, subscribe, unsubscribe<BR>

PHP Mailing List kindly supported by<BR>

<a href="http://www.vcaa.vic.edu.au" target="_blank">http://www.vcaa.vic.edu.au</a> - Victorian Curriculum and Assessment Authority and<BR>

<a href="http://www.vitta.org.au" target="_blank">http://www.vitta.org.au</a> &nbsp;- VITTA Victorian Information Technology Teachers Association Inc<BR>
</blockquote></div><BR>
</div>
</blockquote></HTML>
<BR>