I have trouble to figure out a php problem described below.
I have one PHP page that lists several users in a table (the list is generated by PHP). Next to every user, there is a “remove” button. By clicking this button, the page will redirect to a new removal confirmation page, and therefore we need to pass along information about the specifically chosen user.
My idea was to use a $_SESSION array that stores all the information about the chosen user (e.g. first, last name, user ID etc.), but I cannot figure out how the array should store the information for one specific user. Right now I’m using a while loop to generate the list of users:
while ($row = mysqli_fetch_array($data)) {
// Display the user data
echo '<td><strong>' . $row['first_name'] . '</strong></td>';
echo '<td><strong>' . $row['last_name'] . '</strong></td>';
echo '<td>' . $row['nickname'] . '</td>';
...
echo '<td><a href="remove.php">Remove</a>'; // button should be here
echo '</td></tr>';
}
echo '</table>';
How should I make sure that THAT particular Remove link fills the $_SESSION array with that user’s information? Right now, the while loop only creates a bunch of identical remove buttons that do not differentiate between the different users listed in the table. Any help is appreciated!
Using a session is a bad approach in this situation. You probably just want to pass the user id to the removal confirmation page by appending the user id to the linked url:
On the removal confirmation page, you can now access the passed user id with $_GET[“user_id”]