I pass an individual filename as a session to my HTML form name. My first code prints a list of the files in my directory "diary", and I am trying to print the contents of the chosen file in a new page readpage.html But to my horror, since I am passing the session $_SESSION['filename'] as a variable, all my buttons direct me to the last file that my session variable has been assigned to.
What can I do so that each button passes the a different filename? I have found it impossible to pass a php variable as my form input name, since $variable = $_POST[PHP VARIABLE] doesn't work..
note) I'm trying to achieve this by using PHP only (no javascript, mysql tables etc) Thank you
$folder = "diary";
$files = scandir($folder);
$fName = "diary/$file";
?><form method="POST" action="readPage.html"><?
foreach ($files as $file)
{
if($file != "." && $file != "..")
{
$_SESSION["file"] = $file;
$data = file_get_contents("diary/$file");
$info = explode("\t",$data);
?>
<input type="radio" name = <?=$_SESSION["file"] ?> >
<?=$info[0]?> <input type="submit" value = "Go" ><br>
<?
}
}
?></form><?
Receving file readpage.html
echo $_SESSION["file"];
$fOpen = "diary/".$_SESSION["file"];
$fData = file_get_contents($fOpen);