douhu8851 2014-04-07 20:13
浏览 18
已采纳

将表单值存储在多个请求的表中

Here I have an HTML form that stores stores submitted data in a table.

<label> ID: </label><input type="text" name="id"/>
<label>Name :</label><textarea name='Name'></textarea>
<label>Value :</label><br /><input type="text" name="Value"/>
<input type="submit" name="submit" value=" submit "/>

Next time I submit the form, the table refreshes and stores the new values. Instead I need it to add new rows to table and store all previous data I submit during the session. How do I add the new rows without using a data base?

<?php
session_start();
echo  "<table> 
<tr>
<th>ID</th>
<th>Name</th>
<th>Value</th>
</tr>";

if (isset($_POST['submit'])) { 
  echo "
  <tr> 
  <td>".$_POST['id']."</td>
  <td>".$_POST['Name']."</td>
  <td>".$_POST['Value']."</td>
  </tr>";
}
  • 写回答

1条回答 默认 最新

  • 红酒泡绿茶 2014-04-07 21:13
    关注

    Try this:

    <?php
    session_start();
    echo  "<table> 
    <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Value</th>
    </tr>";
    
    if (isset($_POST['submit'])) { 
      $_SESSION['posts'][] = $_POST;
      foreach ($_SESSION['posts'] as $post)
        echo "<tr>
                <td>{$post['id']}</td>
                <td>{$post['Name']}</td>
                <td>{$post['Value']}</td>
            </tr>";
    }
    

    or if you want it all in one page:

    <?php
    session_start();
    echo  "<table> 
    <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Value</th>
    </tr>";
    
    if (isset($_POST['submit'])) { 
      $_SESSION['posts'][] = $_POST;
      foreach ($_SESSION['posts'] as $post)
        echo "<tr>
                <td>{$post['id']}</td>
                <td>{$post['Name']}</td>
                <td>{$post['Value']}</td>
            </tr>";
    }
    
    ?>
    <form action="" method="post">
    <label> ID: </label><input type="text" name="id"/><br>
    <label>Name :</label><textarea name='Name'></textarea><br>
    <label>Value :</label><br /><input type="text" name="Value"/><br>
    <input type="submit" name="submit" value=" submit "/><br>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答