普通网友 2014-11-27 18:25
浏览 49
已采纳

HTML表单名称=会话

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);
  • 写回答

2条回答 默认 最新

  • dongmian5325 2014-11-27 18:36
    关注

    You opened up a php segment here with

    < ?, when it should be < ?php

    this

    ? > < form method="POST" action="readPage.html" > < ?php

    not this

    ? > < form method="POST" action="readPage.html" > < ?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集