skip to Main Content

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?

2

Answers


  1. 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>
    
    Login or Signup to reply.
    1. table need to in the form.

    2. recommended to place the submit button outside the table

       <form method='post'>
       <table>
           <?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 } ?>
           </table>
       <input name='submit' type='submit'></input>
      
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search