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?

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

And here is the simple PHP script:

<HTML>
<TITLE>Action Script for InputForm2</TITLE>
<?php
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>";
}
?>
</HTML>

Dani AI

Generated

A few focused points that clarify what actually breaks a multi-select form and how to handle it safely.

The HTML shape matters (well-formed attributes and explicit option values), but the common server-side mistakes are different: looping over the entire $_POST array or echoing raw values directly. was right to call out markup hygiene, and ’s follow-up shows the form did eventually post data — several small corrections make the behavior predictable and safe.

On the PHP side, target the submitted control specifically, confirm it arrived as an array, and escape output. Example pattern:

if (!empty($_POST['items']) && is_array($_POST['items'])) {
    foreach ($_POST['items'] as $item) {
        echo htmlspecialchars($item, ENT_QUOTES, 'UTF-8') . "<br>\n";
    }
} else {
    echo "No selection made.";
}

HTML tips: ensure the select control indicates multiple selections and that each option has a stable value attribute (labels can differ from values). Use standard, valid attribute syntax so browsers send the expected keys. Closing option tags and proper quoting avoid quirks across parsers — a point raised earlier by .

Quick checklist for debugging:

  • Inspect the sent form with browser dev tools (Network tab) or temporarily var_dump($_POST) to see raw input.
  • Confirm the select control’s name matches what the PHP code checks.
  • Use is_array() to distinguish single vs. multiple inputs.
  • Always escape output with htmlspecialchars() to prevent XSS.

Reference reading: MDN on the select element (select element docs) and PHP documentation for $_POST and htmlspecialchars ($_POST, htmlspecialchars).

Recommended Answers

All 2 Replies

<option>SFone</option>
<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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.