Hello!

I've got the code below which takes data from my db and displays it to the page listing reports submitted by the user. At the end of each row I have button that is supposed to launch a PDF generator so that the user can view their report. I have multiple rows, yet only the bottom row button will work correctly. If I click the submit button on any of the rows prior to the last row, the data for the last report will be displayed. I'd appreciate any help with this. Thanks!

<form name="vin_report_table" action="reportPDF.php" method="post">
        <table>
<?php
    $color = "#cccccc";
    echo "<tr bgcolor=\"" . $color . "\"><td><strong>VIN</strong></td>";
    echo "<td><strong>Year </strong></td>";
    echo "<td><strong>Model </strong></td>";
    echo "<td><strong>Date </strong></td><td></td></tr>";
    echo "<br>";
    
    if(mysql_num_rows($result)){
    while($row = mysql_fetch_assoc($result)){
            
            if ($color == "#cccccc") {
                $color = "#ffffff";
            } else {
                $color = "#cccccc";
            }
            
            echo "<tr bgcolor=\"" . $color . "\"><td>".$row['vin_full']. "</td>
          <td>" . $row['vin_model'] . "</a></td>
              <td>" . $row['vin_year'] . "</a></td>
                  <td>". $row['vreport_timestamp'] . "</a></td>
                      <td><input type=\"hidden\" name=\"u\" value=\"".$username."\"/>
                          <input type=\"hidden\" name=\"rid\" value=\"".$row['report_id']."\"/>
                          </><input type=\"submit\" value=\"View Report\" /></td></tr>\n";
            


        }
    } else {
        echo "<tr><td>No reports on record</td></tr>";
    }
?>
        </table>
    </form>

Thanks!

Either use new form for each row, or change the field names for each row.

Your form has form elements with the same name in each row so $_POST array contains only the last set of values I guess. Try to enclose form elements that belong to one row in <form></form> tags (so each form has only one submit button).

Great tips! I went and made each row into a Form and that worked perfectly. Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.