首页 > 解决方案 > 从数据库中获取特定值并将其显示在另一个页面上的文本框中

问题描述

当我单击 entry.php 中第一个条目的编辑按钮时,我重定向到 editentries.php 页面。在那里,我只想在该页面上显示第一个条目的详细信息以对其进行编辑。但是当我单击第一个条目的编辑按钮时,我看到的是数据库中的所有条目,而不是一个特定的条目。帮我看看我该怎么办。

这是我的条目.php

 <?php
            $result01 = mysqli_query($conn,"SELECT * FROM feedetails");
        while($res=mysqli_fetch_assoc($result01))
        {
        echo '
          <tr>
            <td><input type="checkbox"></td>
            <td>'.$res["name"].'</td>
            <td>'.$res["address"].'</td>
            <td>'.$res["email"].'</td>
            <td>'.$res["phoneno"].'</td>
            <td>'.$res["subjects"].'</td>
            <td>'.$res["price"].'</td>
            <td><form method="post" action="editentries.php"><input type="submit" name="edit" class="btn btn-primary" value="Edit"></form></td>
            <td><form method="post" action="deleteentries.php"><input type="submit" class="btn btn-danger" value="Delete" ></form></td>
          </tr>';
      }
          ?>

这是editentries.php

<?php

if(isset($_POST['edit'])){

//$selectid=mysqli_query($conn,"SELECT * FROM feedetails GROUP BY id");
$selectname=mysqli_query($conn,"SELECT * FROM feedetails GROUP BY name");
$selectaddress=mysqli_query($conn,"SELECT * FROM feedetails GROUP BY address");
$selectemail=mysqli_query($conn,"SELECT * FROM feedetails GROUP BY email");
$selectphoneno=mysqli_query($conn,"SELECT * FROM feedetails GROUP BY phoneno");
$selectprice=mysqli_query($conn,"SELECT * FROM feedetails GROUP BY price");


?>

    <form>
      <div class="form-group row">
        <label for="inputEmail3" class="col-sm-2 col-form-label">Applicant ID:</label>
        <div class="col-sm-10">
          <select class="form-control">
          <?php  
           for($i=1;$i<=40;$i++)
           {
              echo '<option value="' . $i . '">' . $i . '</option>';  
           }

           ?>
          </select>
        </div>
      </div>
      <div class="form-group row">
        <label for="inputEmail3" class="col-sm-2 col-form-label">Name:</label>
        <div class="col-sm-10">
          <?php  while($res=mysqli_fetch_array($selectname)){
            echo '<input type="text" class="form-control" id="inputEmail3" placeholder="'.$res['name'].'" >';
          }
           ?>
        </div>
      </div>
      <div class="form-group row">
        <label for="inputPassword3" class="col-sm-2 col-form-label">Address:</label>
        <div class="col-sm-10">
         <?php  while($res=mysqli_fetch_array($selectaddress)){
            echo '<input type="text" class="form-control" id="inputEmail3" placeholder="'.$res['address'].'" >';
          }
           ?>
        </div>
      </div>
      <div class="form-group row">
        <label for="inputPassword3" class="col-sm-2 col-form-label">Phone no.:</label>
        <div class="col-sm-10">
         <?php  while($res=mysqli_fetch_array($selectphoneno)){
            echo '<input type="text" class="form-control" id="inputEmail3" placeholder="'.$res['phoneno'].'" >';
          }
           ?>
        </div>
      </div>
      <div class="form-group row">
        <label for="inputPassword3" class="col-sm-2 col-form-label">Email ID:</label>
        <div class="col-sm-10">
         <?php  while($res=mysqli_fetch_array($selectemail)){
            echo '<input type="text" class="form-control" id="inputEmail3" placeholder="'.$res['email'].'" >';
          }
           ?>
        </div>
      </div>
      <div class="form-group row">
        <div class="col-sm-10">
          <button type="submit" class="btn btn-primary">Update</button>
        </div>
      </div>
    </form>

当我单击编辑按钮时,我只想从数据库中获取并显示一个特定条目。但我看到了数据库中的所有条目。

标签: php

解决方案


像这样更新 html form(entries.php) //首先你需要传递 id

 <tr>
    .
    .
    .
    <td><form method="post" action="editentries.php"><input type="hidden" value="'.$res["id"].'" name="editid"><input type="submit" class="btn btn-danger" value="Edit"></form></td>
</tr>

in php editentries.php // 你需要用 where 获取 id 和更新条件

if(isset($_POST['edit']) && isset($_POST['editid'])){
  $id = $_POST['editid'];
  $selectname=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY name");
.
.//Same for other queries

推荐阅读