I am trying to use a button to POST a variable from one page in php to another. I have retrieved the variable "Class" from the table "Class" and now want to POST it to the viewmembers.php page, however am unsure how to do this.
Here is the code:
<?php
    
session_start();
    
include_once('connection.php');
    
    
$stmt = $conn->prepare("SELECT * FROM class WHERE Username = :Username");
    
$stmt->bindParam(':Username', $username);
$stmt->execute();  
    
while ($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
    echo("Class Code: ".$row["Class"]." <br> Username: " .$row["Username"]." <br> Subject: ".$row["SubjectName"]."<br>");
    echo("<button onclick= \"location.href='viewmembers.php'\">View Members</button><br><br>");
    
}
?>
I have tried using session variables, however since I have retrieved multiple rows from the table, the session variable only stores the last row that was retrieved from the table. Any help would be appreciated.
 
     
    