not getting selected item in select option tag (form) [duplicate]

3 views
0

Hello, i’m trying to make a simple form using html and php, then fetch some data from a database, make the data inside a tag, then according to what gets chosen, on submit, i take that item.

Here is the code, that does almost everything but it wouldn’t send the selected item in GET nor in POST:

    <!DOCTYPE html>
  <html>
    <head>
        <title>testing lel</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body >
        <form action="test.php" method="GET" name="test" >
            <label for="id">ID: <input type="number" name="id" > </label> <br/>

            <label for="type" form="test">type: <select id="type" name="type" form="test" >
                <option label=" "> </option>
          <?php 
            $host='localhost';
          $uname='root';
          $pwd='';
          $db="cc";

          $ID = 0;

          $con = mysql_connect($host,$uname,$pwd) or die("connection failed");
          mysql_select_db($db,$con) or die("db selection failed");

          $options=mysql_query("SELECT DISTINCT Type FROM seance1",$con);
          while($row = mysql_fetch_array($options))
            {
                echo '<optgroup label="'.$row['Type'].'">';

            $types=mysql_query("SELECT sujet FROM seance1 where Type="".$row['Type'].""",$con);

                while($row2 = mysql_fetch_array($types))
                {
                echo '<option value="'.$row2['sujet'].'" label="'.$row2['sujet'].'"></option>';
                }

                echo '</optgroup>';
            }
                    echo '</select> </label>';
                    echo "<br/><br/> <input type="submit" name="submit"> ";

            if ((isset($_GET['submit'])))
            {
                echo $_GET['type'];

            }

          echo "<br/><br/> ";

          mysql_close($con);
          ?>

    </body>
  </html>

It should echo the selected item after i press submit.

But instead, i get this error:
“Notice: Undefined index: type in C:……test.php on line 49”
and in the link up, there is totally no ‘type’ input found, only the id and the submit:
“?id=&submit=Submit”

EDIT:
here’s the output (after indentation)

    <select id="type" name="type" form="test" >
<option label=" "> </option>
    <optgroup label="Game">
        <option value="RubikCube" label="RubikCube"></option>
        <option value="Chess" label="Chess"></option>
        <option value="Xbox" label="Xbox"></option>
        <option value="Quiz" label="Quizz"></option>
        <option value="Escape" label="Escape"></option>
        <option value="Enigma" label="Enigma"></option>
    </optgroup>
    <optgroup label="Conferance">
        <option value="Laravel The PHp Framework" label="Laravel The PHp Framework"></option>
        <option value="Bulding Scalable WebAPP" label="Bulding Scalable WebAPP"></option>
        <option value="Micro Controller" label="Micro Controller"></option>
        <option value="Big Data" label="Big Data"></option>
        <option value="Web App Security" label="Web App Security"></option>
        <option value="Achieving Security 101" label="Achieving Security 101"></option>
        <option value="Power of Ux" label="Power of Ux"></option>
        <option value="Demestifying Web App" label="Demestifying Web App"></option>
        <option value="Unity" label="Unity"></option>
        <option value="E-Health" label="E-Health"></option>
        <option value="Android" label="Android"></option>
        <option value="Monetization" label="Monetization"></option>
        <option value="Firebase" label="Firebase"></option>
    </optgroup>
    <optgroup label="Workshop">
        <option value="Arduino" label="Arduino"></option>
        <option value="Internet Of Things" label="Internet Of Things"></option>
        <option value="Android" label="Android"></option>
    </optgroup>
</select>