I am somewhat a noob on php, yet I have been trying for ages to solve this problem:
I have a MySQL ARRAY from which I want to extract data to put in a SESSION via a link. That should be pretty simple, but I’m going crazy trying to find the solution.
Here is what I’m trying to do:
ARRAY output:
Name – Country
James – Germany (link)
George – Mexico (link)
Tom – France (link)
Peter – Ireland (link)
On the end of each ARRAY output I want a link. And when the link is pressed the specific VARIABLE is sent to the SESSION and the user is also sent to a new page, where the SESSION will be picked up again.
The only VARIABLE I can manage to sent to the SESSION is always the last one, ex. “Peter – Ireland”, Even if I press on the link next to ex. George. Frustrating!!
What to do?
You need to pass value in URL, no need of SESSION..
If you take value in SESSION variable it always overwrite it. that's why you get the last value only. so better way is just pass the name and country in URL..
<a href="yourpage.php?name=James&country=Germany">James – Germany</a>
Then get the value of it on yourpage.php
echo $_REQUEST['name']; // James
echo $_REQUEST['Country']; // Germany