通过一页上的多个提交按钮显示数据

时间:2018-08-24 11:03:23

标签: php html

我有一个包含用户表的HTML页面。有一个编辑按钮,按下该按钮可在同一页上的表单中显示用户名,名字和姓氏(这有效)。

这是另一个表单,带有中断名称的下拉列表和一个提交按钮。按下时,将显示休息时间名称的开始时间和结束时间(这也有效)

按下提交按钮后,用户名,名和姓数据将消失。我需要的是在按下“提交”按钮后仍然可以显示这些数据。

这可能吗?如果可以的话,请告诉我下面创建的代码以及页面的屏幕截图:

<?php  include('stackoverflowtest3_inc.php');
<?php 
  if (isset($_GET['edit']))
  {
    $id = $_GET['edit'];
    $update = true; 
    $record = pg_query($db, "SELECT * FROM test3 WHERE id=$id");
    if (count($record) == 1 ) 
     {
      $n = pg_fetch_array($record);
      $username = $n['username'];
      $firstname = $n['firstname'];
      $lastname = $n['lastname'];
    }

      }
?>
<!DOCTYPE html>
<html>
<head>

  <link rel="stylesheet" type="text/css" href="setupstyle31.css">
</head>
<body>
  <?php $results = pg_query($db, "SELECT * FROM test3"); ?>
       <!--creation of the table to display the users data-->
       <table> 
          <thead> 
            <tr> 
              <th>User Name</th>  
              <th>First Name</th> 
              <th>Last Name</th>  
              <th>Break 1 Name</th>  
              <th>Break 1 Start</th>  
              <th>Break 1 End</th>  
              <th>Action</th>
            </tr> 
        </thead> 
       <?php while ($row = pg_fetch_array($results)) 
         { ?> 
             <tr> 
                <td><?php echo $row['username']; ?></td>
                <td><?php echo $row['firstname']; ?></td>
                <td><?php echo $row['lastname']; ?></td>
                <td><?php echo $row['breaks1name']; ?></td>
                <td><?php echo $row['breaks1start']; ?></td>
                <td><?php echo $row['breaks1end']; ?></td>
                <td> 
                  <a href="stackoverflowtest3.php?edit=<?php echo $row['id']; ?>" class="edit_btn" >Edit</a>
                </td>
            </tr> 
       <?php } ?> 
      </table>

<!-- Start of the Input Form which displays the username firstname and lastname of user line which edit has been pressed This is read only and canot be edited on the table-->

<form method="post" action="stackoverflowtest3_inc.php" > 
    <input type="hidden" name="id" value="<?php echo $id; ?>"> 
        <div class="input-group"> 
          <label>User Name</label> 
           <input type="text" name="username" value="<?php echo $username; ?>">              
              <label>First Name</label>
               <input type="text" name="firstname" value="<?php echo $firstname; ?>">
                <label>Last Name</label>
                 <input type="text" name="lastname" value="<?php echo $lastname; ?>">
        </div>

<!-- Start of the inputting of break Data form-->
   </form>
        <div class="input-group">
          <form name="display" action="stackoverflowtest3.php" method="POST" >
            <select name="breakname">
              <?php
                $db1 = pg_connect("host=localhost dbname=vcbv3 user=postgres");
                $result = pg_query($db1, "SELECT breakname FROM breaks");
               if (!$result) 
                { 
                 echo "An error occurred.\n";
                 exit;
                }
                 while ($row = pg_fetch_row($result)) 
                {
                echo "<option value='$row[0]'> $row[0] </option>\n";
                }
              ?>               
               <li><input type="submit" name="submit"   /></li>
            </select>      
              <?php
                  if (isset($_POST['breakname']))
                   { 
                    $db = pg_connect("host=localhost dbname=vcbv3 user=postgres");
                    $result1 = pg_query($db, "SELECT * from breaks WHERE breakname= '".$_POST['breakname']."'");
                    $row = pg_fetch_assoc($result1);
                   }   
                  if (isset($_POST['submit']))
                   { 
                     echo "<ul>
                               <form name='update' action='stackoverflowtest3.php' method='POST' >
                                <li>Break Name:</li><li><input type='text' name='user_first_name_updated' value='$row[breakname]' /></li>
                                <li>Break Start:</li><li><input type='text' name='user_last_name_updated' value='$row[startat]' /></li>
                                <li>Break Finish:</li><li><input type='text' name='breaks1_name_updated' value='$row[finishat]' /></li>                  
                          </ul>";
                    }
              ?>
        </div>
  </form>      
 </body>
</section>

page with edit

page with submit

0 个答案:

没有答案