My simple HTML script below uses SELECT to create a list which should be accessed by the PHP script as an array. Note the products[] definition below.
BUT.... I can't seem to get the script to read the array from$_POST - anyone know how to solve this?

<TITLE>Input Form2</TITLE>
<FORM method="POST" action="FormRead2.php">
<INPUT type="text" name="user">
<TEXTAREA name="address" rows="5" cols="40">
<SELECT name "products[]" multiple>
<option>CTI Desktop
<option>Real-Time Monitor
<INPUT type="submit" name="submit" value="Submit">

And here is the simple PHP script:

<TITLE>Action Script for InputForm2</TITLE>
if(isset($_POST)) {
echo "Welcome <b>".$_POST."</b><P>\n\n";
echo "Your address is:<P>\n\n<b>".$_POST."</b><p>\n\n";
echo "Your product choices are:<p>\n\n";
echo "<UL>\n\n";

foreach($_POST as $value) {
echo "<LI>$value<BR>\n";

echo "</UL>";

Edited by happygeek: fixed formatting

12 Years
Discussion Span
Last Post by mcldev

<option>CTI Desktop</option>
<option>Real-Time Monitor</option>

I don't really care to connect to a server to try this out, but even if this doesn't fix the problem, you should always use closing tags. Even <br> tags are now <br /> tags, for instance.


The Solution

In case you are interested, the key to getting the HMTL script to pass SELECT data is to 1) declare your variable as an array, i.e. use brackets like product[], 2) Then in your PHP action script make sure you treat product as an associative array, i.e. forech($_POST as $key=>$value). Note, this allows you to pass over multiple selections.

Also, note the use of _POST. If you are still using PHP4 it is important to look at _SERVER, _GET, etc. because you will undoubtly cross their path during forms development. You can use the long names like HTTP_POST_VARS but the shorter names are more managable.

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.