0

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!

Edited by oamunoz: clarified statement

3
Contributors
3
Replies
11
Views
6 Years
Discussion Span
Last Post by oamunoz
0

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).

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.