Update an array via a form POST method and display as list

Everyone should know this…interesting problem 2Bsolved! Fun

Build and display an array of anything, strings or numbers…say, a list of phone numbers, one at a time, input from a form.

Brian.

My trial…I don’t know arrays too well, pls look…
[php]

<?php # Script 16.5 - bingo6.php if (isset($_POST['submitted'])) { $_POST[$x]=($_POST[$x]+1); $x=0; $phoneNo= $_POST['phoneNo']; $sms_list = array(); $sms_list[$_POST[$x]]=$phoneNo; echo $_POST['phoneNo']; ?>

Telephone No:

Send: [/php]

First, is this page posting to itself? Is the page you posted, the bingo6.php file?

If so, you must remember that this page exists on a server.
It runs SERVER-SIDE processing which spits out code mixed with the HTML and sends to the CLIENT.
The client is a browser. So, your code will start over EVERY time you send it to itself.

Therefore the code you posted will set $x and $sms_list to zero every time it is posted. (to itself!)

If you are attempting to send an array to yourself, you can do this by storing it into a field on the page.
Create a hidden field and have it’s “value=” to be loaded with the new value. In the PHP section, you
would take the posted value of the hidden field, add the posted phone number to it and display it in the
value of the hidden field. Thus adding a new number to it. Did that make sense?

Well, try again and good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service