Search code examples
phphtmlformshtml-table

php html - input tag is displayed before php although php is written first


i wrote a form with some php loop to insert array and numbers

a form inside a table with tr td to get fixed width

php array within form, then for loops with html tr td

at the end of the form, <input>

<table>
<form method='post'>

<?php
$row=array(
'databaseName',
'tableName',
'nColumns',
'columnName',
'dataType',
'dataSize',
'null',
'indexing');

for($k=0; $k<=7; $k++){
?>
<tr><td><?php echo $row[$k]; ?></td>
<td><input name='<?php echo $row[$k]; ?>' type='text'>
</input></td></tr>

<?php if($k==2){ ?>
<tr>
<td>Number of Columns</td>
<td><select onchange='nColumns()'>

<?php for($i=1; $i<=12; $i++){ ?>
<option id='<?php echo $i; ?>'><?php echo $i; ?></option>
<?php } ?>
</select></td></tr><?php } ?>
<?php } ?>

<input name='submit' type='submit'></input>
</form></table>

but the input is displayed first before php loops. why? and how do i make the submit button to be at the bottom?


Solution

  • You are facing this issue because your submit button is outside the table structure, specifically outside the <tr> and <td>.

    Try the below code:

    <form method='post'>
        <table>
    
            //Your code
    
            <tr>
                <td>
                    <input name='submit' type='submit'></input>
                </td>
            </tr> 
        </table>
    </form>