Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To read a selected option in PHP, give its <select> a name, give each <option> the value you want submitted, then read the named field from $_POST or $_GET according to the form’s method.

Submit the selected option with a form

The option’s value is submitted as data; the text between its tags is the label shown to the user. The name on the select becomes the key PHP uses to access that submitted value.

<form action="process.php" method="post">
  <label for="color">Color</label>
  <select name="color" id="color">
    <option value="blue">Blue</option>
    <option value="green">Green</option>
  </select>
  <button type="submit">Submit</button>
</form>

Here, choosing “Blue” submits blue, not the label “Blue.” PHP makes submitted form fields available through its external-variable superglobals; see PHP: Variables From External Sources.

Read and safely display the submitted value

For the POST form above, the field is $_POST['color']. Check that it exists before using it, validate it against the values your application accepts, and escape it if you display it in HTML.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<?php
$color = $_POST['color'] ?? '';

$allowedColors = ['blue', 'green'];
if (!in_array($color, $allowedColors, true)) {
    http_response_code(400);
    exit('Invalid color');
}

echo htmlspecialchars($color, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');

The null-coalescing operator supplies an empty string when the key is absent; it does not validate the value. Form data arrives as external input and should not be treated as trusted or already converted to an application-specific type. PHP’s forms tutorial demonstrates htmlspecialchars() to encode HTML-special characters when rendering submitted content.

Choose the superglobal that matches the form method

Form method PHP array Typical use
post $_POST['color'] Use for form submissions that should not put the fields in the URL.
get $_GET['color'] Useful for searches when the query should be bookmarkable or cacheable and the action is not intended to change anything the client cares about.

For a GET form, change method="post" to method="get" and read $_GET['color']. PHP documents the corresponding superglobals and discusses GET and POST in its forms tutorial.

Read several selected options

For a select that allows multiple choices, use square brackets in its name. PHP then exposes the submitted selections as an array.

<select name="choices[]" multiple>
  <option value="one">One</option>
  <option value="two">Two</option>
</select>

With a POST form, read the values from $_POST['choices']; with a GET form, use $_GET['choices']. Check that the key exists and validate each item before using it. PHP’s manual shows the same array-style naming approach for a multiple select.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot a missing or unexpected value

  • Inspect the rendered HTML and confirm the select has the expected name and each option has the intended value.
  • Confirm the form’s method and read the matching array: $_POST for POST or $_GET for GET.
  • If the key is absent, check that the form was submitted, the select is inside that form, and a choice was selected. Use a presence check or a fallback before indexing into the superglobal.
  • If the value is unexpected, compare the submitted option value—not its visible label—with the values your application allows.

If an option has no explicit value, HTML derives its submitted value from the option’s text; setting the value explicitly makes the data your application receives clear. See MDN’s HTML select reference.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.