Re: [PHP] How to retrieve form data?
You are correct, and I must apologize. In addition to the modifications below I added a pair of brackets to the select clause: select name=item[] After removing those the $_POST array looks much better and I was able print the selected item using echo Selected item is: .$_POST['item']; Results now: --- Using printr, $_POST array contains: Array ( [item] = select item 1 ) Selected item is: select item 1 --- Thank you very much for your responses and willingness to help one who is just beginning to learn how to use PHP. I am now on my way. John Nichel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Gregg Nelson wrote: snip Clicking on the submit button now produces: -- Request Method: POST Using foreach loop, $_POST array contains: Array Using printr, $_POST array contains: Array ( [item] = Array ( [0] = select item 1 ) ) -So what exactly does this mean?: $Post is an array thatconsists of one item that is also an array, that being the item array consisting of one entry containing the select string?If so, can I access the item array itself? I tried this in the script but nothing was echoed:echo $item[0] No, that's not how it should be coming across. Not unless you modified your original form to send item as an array (like you would do if it was a multi-select). If your HTML form hasn't changed from how you have it below, and 'item' is still coming across as an array, you have a problem sowhere else. original form? --- html form action=?php $_SERVER['PHP_SELF'] ? method=post select name=item option value=select item 1 item 1 /option option value=select item 2 item 2 /option /select input type=submit value=Submit /form ?php echo Request Method: .$_SERVER['REQUEST_METHOD'].br /; if ($_SERVER['REQUEST_METHOD'] == POST): echo '$_POST array contains:'.br /; foreach ($_POST as $value) {echo $value.br /;} endif; ?/html -- By-Tor.com ...it's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How to retrieve form data?
The first execution of the file below produces the expected output: Request Method: GET Clicking on the Submit button outputs: Request Method: POST $_POST array contains: Array Why don't I see one of the values from the select item? --- html form action=?php $_SERVER['PHP_SELF'] ? method=post select name=item option value=select item 1 item 1 /option option value=select item 2 item 2 /option /select input type=submit value=Submit /form ?php echo Request Method: .$_SERVER['REQUEST_METHOD'].br /; if ($_SERVER['REQUEST_METHOD'] == POST): echo '$_POST array contains:'.br /; foreach ($_POST as $value) {echo $value.br /;} endif; ?/html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to retrieve form data?
Gregg Nelson wrote: The first execution of the file below produces the expected output: Request Method: GET Clicking on the Submit button outputs: Request Method: POST $_POST array contains: Array Why don't I see one of the values from the select item? --- html form action=?php $_SERVER['PHP_SELF'] ? method=post select name=item option value=select item 1 item 1 /option option value=select item 2 item 2 /option /select input type=submit value=Submit /form ?php echo Request Method: .$_SERVER['REQUEST_METHOD'].br /; if ($_SERVER['REQUEST_METHOD'] == POST): echo '$_POST array contains:'.br /; foreach ($_POST as $value) {echo $value.br /;} endif; ?/html Your foreach loop isn't going to print what _you're_ expecting. foreach ( $_POST as $key = $value ) { echo ( $value . br / ); } but print_r() would be much easier... echo ( pre ); print_r ( $_POST ); echo ( /pre ); -- By-Tor.com ...it's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to retrieve form data?
Thank you for your very quick answer. As you may have already guessed, I'm new to PHP, and struggling with the the most basic operations. I modifed the 'echo' as suggested and also added a 'printr statement. The modified portion of the script is below if ($_SERVER['REQUEST_METHOD'] == POST): echo 'Using foreach loop, $_POST array contains:'.br /; foreach ( $_POST as $key = $value ) { echo ( $value . br / );} echo 'Using printr, $_POST array contains:'.br /; echo ( pre ); print_r ( $_POST ); echo ( /pre ); endif; Clicking on the submit button now produces: -- Request Method: POST Using foreach loop, $_POST array contains: Array Using printr, $_POST array contains: Array ( [item] = Array ( [0] = select item 1 ) ) -So what exactly does this mean?: $Post is an array thatconsists of one item that is also an array, that being the item array consisting of one entry containing the select string?If so, can I access the item array itself? I tried this in the script but nothing was echoed:echo $item[0] John Nichel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Gregg Nelson wrote: The first execution of the file below produces the expected output: Request Method: GET Clicking on the Submit button outputs: Request Method: POST $_POST array contains: Array Why don't I see one of the values from the select item? -- -- --- html form action=?php $_SERVER['PHP_SELF'] ? method=post select name=item option value=select item 1 item 1 /option option value=select item 2 item 2 /option /select input type=submit value=Submit /form ?php echo Request Method: .$_SERVER['REQUEST_METHOD'].br /; if ($_SERVER['REQUEST_METHOD'] == POST): echo '$_POST array contains:'.br /; foreach ($_POST as $value) {echo $value.br /;} endif; ?/html Your foreach loop isn't going to print what _you're_ expecting. foreach ( $_POST as $key = $value ) { echo ( $value . br / ); } but print_r() would be much easier... echo ( pre ); print_r ( $_POST ); echo ( /pre ); -- By-Tor.com ...it's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How to retrieve form data?
Gregg Nelson wrote: snip Clicking on the submit button now produces: -- Request Method: POST Using foreach loop, $_POST array contains: Array Using printr, $_POST array contains: Array ( [item] = Array ( [0] = select item 1 ) ) -So what exactly does this mean?: $Post is an array thatconsists of one item that is also an array, that being the item array consisting of one entry containing the select string?If so, can I access the item array itself? I tried this in the script but nothing was echoed:echo $item[0] No, that's not how it should be coming across. Not unless you modified your original form to send item as an array (like you would do if it was a multi-select). If your HTML form hasn't changed from how you have it below, and 'item' is still coming across as an array, you have a problem sowhere else. original form? --- html form action=?php $_SERVER['PHP_SELF'] ? method=post select name=item option value=select item 1 item 1 /option option value=select item 2 item 2 /option /select input type=submit value=Submit /form ?php echo Request Method: .$_SERVER['REQUEST_METHOD'].br /; if ($_SERVER['REQUEST_METHOD'] == POST): echo '$_POST array contains:'.br /; foreach ($_POST as $value) {echo $value.br /;} endif; ?/html -- By-Tor.com ...it's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php