• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP (Newbie in php) How can I print the "text" of a select option (form)? (help)


New Coder
Hello, new here, english is not my native lenguage but i'm gona try to explain what I need to learn. Sorry in advance, I'm learning on my own and may make a lot of mistakes

The problem is this: I have 3 documents:

- Form.php -> here is the form (first photo)

<form action="index.php?seccion=print" method="POST" enctype="multipart/form-data">
<select name="item" id="item">
include_once 'item.php';
foreach ($options as $value => $option) :
echo "<option value=\"$value\">$option</option>";

- Item.php -> here are the select options inside an array that I linked to the other 2 .php documents

$options = [
'H' => 'option 1',
'O' => 'option 2',
'E' => 'option 3',

- Print.php -> I want the results to print her

include_once 'item.php';

<!!!!---don't know what code to put here ---!>

I want the option(item) selected in document form.php to be printed in print.php, but i only get the string and the array position printed when I tried different things.
Am I explaining myself? Can anyone help me?

Thanks in advance,
hope I have not broken any rules of the forum.


Active Coder
Try this:

if(isset($_POST["item"])) {
    echo "The Result Is: " . $options[$_POST["item"]];

The value submitted by the form is the key to the array, so you have to access the key of the array to display the value.