I am trying to store a PHP session variable through a HTML button. For example I run a FOR loop contains a HTML button and it shows up 5 buttons: A ,B ,C, D, E. I want to click on the button C and it will redirect to a new page that shows up (echo) $C
How could I achieve that?
I have tried the following code:
for($i=0;$i<count($hashtag);$i++){
echo '<button type="submit" name="insert" value="';
$_SESSION["hashtag_search"]=$hashtag[$i];
echo '"><span class="label label-danger" ><a target="_blank" href="http://link.net/search-hashtag.php">'.$hashtag[$i].' ('.$hashtag_count[$i].')</a></span></button>';
}
on the search-hashtag.php i got
echo $_SESSION["hashtag_search"];
but the SESSION variable would store the last $hashtag[$i] (when $i maxed) not the $hashtag[$i] of the clicked button
$_SESSION["hashtag_search"]=$hashtag[$i];so at last in for loop session always store the last$hashtag[$i]