PHP通过提交按钮发送数据(表名)时始终显示最后创建的表

So, im a little new to php and i need to send a table name to another php file this is the code i already have:

<form action="clases.php" method="GET">

        <?php
         $result= mysql_query('SHOW TABLES', $conn) or die ('cannot show tables');
    while($tablename = mysql_fetch_array($result)){
        $a=0;
        $table = $tablename[$a];




       echo '<table cellpadding="0" cellspacing="0" class="db-table">';
       echo '<tr>';


        echo '<td>',$table,'<input type="hidden" name="Class" value="' . $table . '" />';
        echo '</td>';
        echo "<td><input type='submit' name='Entrar' value='Enter'></td>";
        echo "<td><input type='submit' name='Eliminar' value='Delete'></td>";
        echo '</tr>';
        echo '</table><br />';
        ++$a;
      }
        ?>
</form>

Right now i just need the Enter button working, when i submit it i should send to another php file with just:

<?php $classname = $_GET['Class']; echo $classname; ?>

But it always gives me the last table i created, so if a have 3 tables created

  • Table A
  • Table B
  • Table C

the $classname always shows "Table C".

Sorry about the english, its not my first lenguaje.

It is because the code is executed in a loop. By the time you press enter the loop is complete and the only available table is the last one created which it table C.You can use an array of tables to store every table string created.Retrieve it and then attach an event