First Second ThirdHow vị I get the value from the select option & store it into a variable for future use, in PHP?
Highest score (default) Trending (recent votes count more) Date modified (newest first) Date created (oldest first)
Use this way:
$selectOption = $_POST<"taskOption">;But it is always better lớn give values to lớn your tags.
Bạn đang xem: How to get selected values from select option in php 8
First Second Third
You can access values in the $_POST array by their key. $_POST is an associative array, so khổng lồ access taskOption you would use $_POST<"taskOption">;.
Make sure to kiểm tra if it exists in the $_POST array before proceeding though.
First Second Third process.php
You can vì chưng it lượt thích this, too:
"; break; case "value2": echo "value2"; break; default: # code... Break; }}?> Value 1 Value 2 for php8+ versions, you can use match expression:
$select = $_POST<"select1"> ?? "";$result = match ($select) "value1" => "this is value1", "value2" => "this is value2", mặc định => "unknown value",;echo $result;
Depends on if the form that the select is contained in has the method set khổng lồ "get" or "post".
Xem thêm: lập trình hướng đối tượng php
If then the value of the select will be located in the super global array $_GET<"taskOption">.
If then the value of the select will be located in the super global array $_POST<"taskOption">.
To store it into a variable you would:
$option = $_POST<"taskOption">A good place for more information would be the PHP manual: http://php.net/manual/en/tutorial.forms.php
The index of the $_POST array is always based on the value of the name attribute of any HTML input.
-- html tệp tin --
Kabul Herat Mazar -- php file --
$city = (isset($_POST<"city">) ? $_POST<"city">: null);print("city is: ".$city<0>);
Highly active question. Earn 10 reputation (not counting the association bonus) in order to lớn answer this question. The reputation requirement helps protect this question from spam and non-answer activity.
Site design / biểu tượng logo © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA. Rev2022.11.11.43030