我想选择一个表并使用我选择的表中的相同数据创建一个表

These are my problems:

  1. The value I selected from the two drop down list will change back to its default value when the browser implements the function onchange in the form.

  2. I want to create a table and the data's should be the same with the the table I selected from the second drop down list.

This is my code

PHP

<?php
   $connectDatabase = mysql_connect("localhost","root","") or die(mysql_error());
   $tables = array();
     if(isset($_POST['select_db'])) 
     { // if its submitted 
         $select_db = $_POST['select_db'];
         $mysql_select_db = mysql_select_db($select_db,$connectDatabase);
         $drop_table = mysql_query("DROP TABLE pdf_table",$connectDatabase);
         $query = "SHOW TABLES FROM $select_db";
         $mysql_query = mysql_query($query,$connectDatabase);
       while($row =mysql_fetch_assoc($mysql_query)) 
       {
          $tables[] = $row['Tables_in_' . $select_db]; // use associative instead
       }
    }
    if(isset($_POST['select_table']))
    {
        $select_table = $_POST['select_table'];
        $db = mysql_select_db($select_db,$connectDatabase);
        $query_select = "Create Table pdf_table AS ( SELECT * FROM $select_table)";
        $select_query = mysql_query($query_select,$connectDatabase);
    }
    ?>

HTML CODE

 <form class="Search_Form" action="moduleindex.php" method="POST">
        <select name="select_db" onchange="this.form.submit();">
            <option disabled selected>Select Database</option>
            <option>section_masterfile</option>
        </select>
        <select onchange="this.form.submit();" name="select_table">
            <option disabled selected>Select Table</option>
            <?php foreach($tables as $table): ?>
            <option value="<?php echo $table; ?>"><?php echo $table; ?></option>
            <?php endforeach; ?>
        </select>
</form>

Add check in foreach loop while generating Options if some value posted and value is equal to loop value

  <select onchange="this.form.submit();" name="select_table">
                <option disabled selected>Select Table</option>
                <?php foreach($tables as $table){?>
                 <?php 
                 $selected ="";
                 if(isset($_POST['select_table']) && $_POST['select_table'] ==  $table){ 

                         $selected = 'selected="selected"'; 


                     } ?>
                <option value="<?php echo $table; ?>"  <?php echo $selected ;?>  ><?php echo $table; ?></option>
                <?php }?>
            </select>