为什么这段代码不会在我的屏幕上发布所选的选项?

<?php
if ($_POST['submit']){
    $myvalue=$_POST['sub1'];
    echo $myvalue;
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form action='test322.php' method='POST'>
           <input type='submit' name='submit' value='submit'>
        </form>
        <select id='sub1' name='sub1'>
            <option value="fsd1">dssdds1</option>
            <option value="fsdff2">dssfddds2</option>
            <option value="fsdff3">dssfddds3</option>
        </select>
    </body>
</html>

Hello all, could anyone tell me why this code doesn't post the selected option on my screen? Thank you in advance!

Look at the end-tag of </form> it is way to high. Put it under the </select> and you will be happy ;)

<?php
if (isset($_POST['submit'])){
    $myvalue=$_POST['sub1'];
    echo $myvalue;
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form action='test322.php' method='POST'>
<select id='sub1' name='sub1'>
            <option value="fsd1">dssdds1</option>
            <option value="fsdff2">dssfddds2</option>
            <option value="fsdff3">dssfddds3</option>
</select>
<input type='submit' name='submit' value='submit'>
            </form>


    </body>
</html>

You need to include the select elements in your form by moving the </form>:

    <form action='test322.php' method='POST'>


        <select id='sub1' name='sub1'>
            <option value="fsd1">dssdds1</option>
            <option value="fsdff2">dssfddds2</option>
            <option value="fsdff3">dssfddds3</option>
            </select>
            <input type='submit' name='submit' value='submit'>
           </form>//add this tag

and you need to check for POST value like so:

if (!empty($_POST)){
{
    $myvalue=$_POST['sub1'];
    echo $myvalue;
}

The select element is not the part of you form.

Move the closing tag of form i.e. </form> after </select>

There’s some mistakes in your code:

1) All data that you need to send in your code needs to be between tags. So, your select isn’t.

2) To get your POST data, just do with $_POST.

<?php
if ($_POST){
    $myvalue = $_POST['sub1'];
    echo $myvalue;
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
            <form action='test322.php' method='POST'>
            <input type='submit' name='submit' value='submit'>
            <select id='sub1' name='sub1'>
                    <option value="fsd1">dssdds1</option>
                    <option value="fsdff2">dssfddds2</option>
                    <option value="fsdff3">dssfddds3</option>
                </select>
        </form>

    </body>
</html>

Hope it helps.

Your select was not part of your form. Try this:

<?php
if (isset($_POST['submit'])){
    $myvalue=$_POST['sub1'];
    echo $myvalue;
}
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form action='lol.php' method='POST'>
            <select id='sub1' name='sub1'>
                <option value="fsd1">dssdds1</option>
                <option value="fsdff2">dssfddds2</option>
                <option value="fsdff3">dssfddds3</option> 
            </select>
            <input type='submit' name='submit' value='submit'>
        </form>  
    </body>
</html>