Q:

Form just gets data from first row in table

I´m having some problems while doing the following, I´m going to try to explain clear what my problem is. I have an HTML table with lots of rows,... and I´m using an HTML form with a button that when you click on it, it sends information to another PHP Script, and it´s working fine, except that it justs gets the information of the first row, no matter where else you click it always sends the data of the first row, this is what I have tried so far:
<?php
$pilotid = Auth::$userinfo->pilotid;
$last_location = RealScheduleLiteData::get_pilot_location($pilotid, 1);
$last_name = OperationsData::getAirportInfo($last_location->arricao);
$biddata = SchedulesData::GetBid($sched_data->bidid);
?>
<h3><b>Job Offers</b></h3>

<ul>

</ul>

<table width="100%" border="0" cellspacing="0" class="table table-striped m0 p0 mt0" style="table-layout:fixed;">
    <tr class="table-header">
        <td colspan="6">Available jobs from <?php echo $last_location->arricao.' ( '.$last_name->name.')' ;?></td>
    </tr>

<?php
if(!$allroutes)
{
?>
    <tr><td align="center">No flights from <?php echo $last_location->arricao.' ( '.$last_name->name.')' ;?>!</td></tr>

<?php
}
else
{
?>
<script src="http://skyvector.com/linkchart.js"></script>

    <tr class="table-header">
    <th width="10%" align="center">Airline</th>
    <th width="10%" align="center">Flight ID</th>
    <th width="10%" align="center">Departure</th>
    <th width="10%" align="center">Arrival</th>
    <th width="10%" align="center">Aircraft</th>
    <th width="30%" colspan=1" align="left">Options</th>
</tr>

<?php
foreach($allroutes as $route)
{
    if(Config::Get('DISABLE_SCHED_ON_BID') == true && $route->bidid != 0)
    {
        continue;
    }
    if(Config::Get('RESTRICT_AIRCRAFT_RANKS') === true && Auth::LoggedIn())
    {
        if($route->aircraftlevel > Auth::$userinfo->ranklevel)
        {
            continue;
        }
    }
?>

<tr class="table-data">
        <td width="20%" align="left" valign="middle"><?php echo '<img src="'.fileurl('/airlines/'.$route->code.'.png').'" alt="'.$airline->name.'" />'; ?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->code . $route->flightnum?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->depicao ;?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->arricao ;?></td>
    <td width="20%" align="left" valign="middle"><?php echo $route->aircraft ;?></td>
        <td width="20%" align="left" valign="middle"><input type="button" value="Job Description" onclick="$('#details_dialog_<?php echo $route->flightnum;?>').toggle()">
        <form id="sbapiform">

        <input type="button" onclick="simbriefsubmit('http://www.virtualaviationgroup.com/index.php/SimBrief');" style="font-size:14px" value="Generate Flight Plan">
<table>
    <tr>
       <?php $planedata=(OperationsData::getAircraftByReg($route->registration)) ;?>
        <td><input type="hidden" name="type" size="5" type="text" placeholder="ZZZZ"  value="<?php echo $planedata->icao ;?>"></td>
    <tr>

    <tr>
         <td><input type="hidden" name="orig" size="5" type="text" placeholder="ZZZZ" maxlength="4" value="<?php echo $route->depicao ; ?>"></td>
    <tr>

    <tr>
       <td><input type="hidden" name="dest" size="5" type="text" placeholder="ZZZZ" maxlength="4" value="<?php echo $route->arricao ; ?>"></td>
    <tr>

    <tr>
       <td><input type="hidden" name="route" placeholder="Enter your route here"></td>
    </tr>

    <tr>
        <td colspan=2></td>
    </tr>

    <tr>
       <td><input type="hidden" name="units" size="5" type="text" placeholder="ZZZZ" maxlength="4" value="KGS"></td>
    </tr>

</table>

<input type="hidden" name="airline" value="<?php echo $route->code?>"> 

<input type="hidden" name="fltnum" value="<?php echo $route->flightnum?>"> 

<?php $today = date("dMy");?>

<input type="hidden" name="date" value="<?php echo $today?>"> 

<?php $deptimes = explode(":", $route->deptime); ?>

<input type="hidden" name="deph" value="<?php echo $deptimes[0]?>">
<input type="hidden" name="depm" value="<?php echo $deptimes[1]?>">    

<?php $arrtimes = explode(":", $route->arrtime); ?>

<input type="hidden" name="steh" value="<?php echo $arrtimes[0]?>">
<input type="hidden" name="stem" value="<?php echo $arrtimes[1]?>">

<input type="hidden" name="reg" value="<?php echo $route->registration?>">    

 <input type="hidden" name="navlog" value="1"> 
<input type="hidden" name="selcal" value="GR-FS">    

<input type="hidden" name="planformat" value="lido">

</form>

       <?php 
        if($biddata->pilotid == $pilotid && $route->bidid != 0)
        {
        ?>
        <input type="button" value="You´re Hired!"
        <?php
        }
        else
        {
        ?>
        <a id="<?php echo $route->id; ?>" class="addbid" href="<?php echo url('/schedules/addbid');?>"><input type="button" value="Accept Job"</a>
        <?php                    
        }
        ?>

    </td>
</tr>

        <td colspan="6">

        <table cellspacing="10" cellpadding="10" border="0" class="table table-striped m0 p0 mt0" id="details_dialog_<?php echo $route->flightnum;?>" style="display:none" width="100%">

            <tr>
            <th align="left" colspan="4">Flight Brefing</th>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspDeaprture:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php
            $name = OperationsData::getAirportInfo($route->depicao);
            echo "{$name->name}"?></b></td>
            <td align="left">&nbsp&nbspArrival:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php 
            $name = OperationsData::getAirportInfo($route->arricao);
            echo "{$name->name}"?></b></td>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspAircraft</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php 
            $plane = OperationsData::getAircraftByName($route->aircraft);
            echo $plane->fullname ; ?></b></td>
            <td align="left">&nbsp&nbspDistance:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->distance . Config::Get('UNITS') ;?></b></td>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspDep Time:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->deptime?> GMT</font></b></td>
            <td align="left">&nbsp&nbspArr Time:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->arrtime?> GMT</font></b></td>
            </tr>
            <tr>
            <td align="left">&nbsp&nbspAltitude:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->flightlevel; ?> ft</b></td>
            <td align="left">&nbsp&nbspDuration:</td>
            <td colspan="0" align="left" ><b>&nbsp
            <?php 

            $dist = $route->distance;
            $speed = 440;
            $app = $speed / 60 ;
            $flttime = round($dist / $app,0)+ 20;
            $hours = intval($flttime / 60);
            $minutes = (($flttime / 60) - $hours) * 60;
            if($hours > "9" AND $minutes > "9")
            {
            echo $hours.':'.$minutes ;
            }
            else
            {
            echo '0'.$hours.':0'.$minutes ;
            }
            ?> Hrs</b></font></td>
            </tr>
            <tr>

            <tr>
            <td align="left">&nbsp&nbspFlight Type:</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php
            if($route->flighttype == "P")
            {
            echo'Passenger' ;
            }
            if($route->flighttype == "C")
            {
            echo'Cargo' ;
            }
            if($route->flighttype == "H")
            {
            echo'Charter' ;
            }
            ?></b></td>
            <td align="left">&nbsp&nbspFlown</td>
            <td colspan="0" align="left" ><b>&nbsp&nbsp<?php echo $route->timesflown ;?></b></td>
            </tr>
            </tr>
            <tr>
            <th align="center"colspan="4">Flight Map</th>
            </tr>
            <tr>
            <td width="100%" colspan="4">
            <?php
            $string = "";
                        $string = $string.$route->depicao.'+-+'.$route->arricao.',+';
                        ?>
<img width="100%" src="http://www.gcmap.com/map?P=<?php echo $string ?>&amp;MS=wls2&MR;MR=240&amp;MX=680x200&amp;PM=pemr:diamond7:red%2b%22%25I%22:red&amp;PC=%230000ff" />

</div>

</tr>
</td>
         </table>   

        </td>
</tr>

<?php
}
}
?>
</table>
<br />
<hr>
<br />

<center><a href="<?php echo url('/FrontSchedules') ;?>"><input type="submit" name="submit" value="Back to Flight Booking System" ></a></center>

I´m sorry guys if this question is not good enough, or it´s already asked, I could not find anything simillar to this. Please don´t be rude with me
Kind Regards!!
--EDIT--
I have these table(which I´m not showing in the code, because it has nothing to do with these)
Table
And each time you click on the button "Generate Flight Plan" it calls the function sending all the variables that I show in the code... The problem is that is just works for the 1st flight shown there. Because if you click in the 2nd, 3rd, 4th, 5th.... whatever it sends the data of the 1st one.

A:

In your file with the tables, change the for loop to this:
<?php
foreach($allroutes as $route)
{
    $formid = isset($formid)? $formid+1 : 1;

Further down on your page where you have your button, change it to this:
<input type="button" onclick="simbriefsubmit('http://www.virtualaviationgroup.com/index.php/SimBrief', <?= $formid ?>);" style="font-size:14px" value="Generate Flight Plan">

...here we added a second argument for the simbriefsubmit() call.
Change your form tag to this:
<form id="sbapiform<?= $formid?>">

...now all forms have unique ID's.
Now we need to add/change a couple of lines in the JS. First on row 742:
function simbriefsubmit(outputpage, formid)
{
    if (!formid) 
        var formid = '';

...then in the same function, on row 768:
do_simbriefsubmit(outputpage, formid);

On row 773:
function do_simbriefsubmit(outputpage, formid)
{
    if (!formid)
        var formid = '';

...row 799 and 804:
setTimeout(function(){do_simbriefsubmit(outputpage, formid);},500);

...and finally on row 813:
var apiform = document.getElementById(sbform + formid);

What we have done is to create unique ID for each form and pass the ID to the javascript functions so they can fetch the correct form.
The if statements in the functions makes sure that won't break any existing calls to that function. 

