I just learned PHP month ago, so now I trapped in a little few days but can't solve it. I have a database with 1 table, 2 column. I want to bring column one value to drop-down in PHP (and I did it!), but I also want to show value of colum two same with drop-down value selected.
Example: If drop-down list value current is 1011, the textbox auto get value "News". But my code never return the textbox's value for the firt value of drop-down !!! And after return value in textbox, it always return to first value in drop-down, not hold back to values I want to choose. Someone can review and help me for this confuse, please? Thank you!
<?php
    $con=mysqli_connect("localhost","root","","my_database_exam"); //connect to my database 
    mysqli_set_charset($con,"utf8"); //set UTF8 for my database
    if(isset($_POST["id_type"])) { //check for the action of select value
        $id_theloai=$_POST["get_id_type"];      
        $ten="SELECT * FROM theloai WHERE ID_TheLoai='".$get_id_type."'";
        $kqten=mysqli_query($con,$ten);
        while($rowten=mysqli_fetch_array($kqten)) {
            $tenresult=$rowten[1];
        }
    }
?>
<form method="POST" action="park.php">
    <label>TYPE OF NEWS</label>
    <select onchange="this.form.submit()" name="id_type">
        <?php
            $sl="SELECT * FROM theloai";
            $result=mysqli_query($con,$sl);
            while ($row=mysqli_fetch_array($result)) {
                echo '<option value="'.$row[0].'">'.$row[0].'</option>';
            }
        ?>
    </select>
    <br>
    <input type="text" name="" value="<?php if(isset($_POST["id_type"])) echo $tenresult; ?>">
</form>
<?php mysqli_close($con);?>
 
    