doushenyu2537 2018-06-11 04:46
浏览 158
已采纳

从数据库中获取特定值并将其显示在另一页的文本框中

When I click on edit button of first entry from entries.php, I redirect to editentries.php page. And there I want to display the details of first entry only on that page to edit them.But when I click on edit button of first entry I am seeing all the entries in database instead of one specific entry. Help me out what should I do.

This is my entries.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>';
      }
          ?>

This is 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>

I want to fetch and display only one specific entry from database when I click on edit button. But I am seeing all the entries from database.

  • 写回答

3条回答 默认 最新

  • doubihuai8468 2018-06-11 04:55
    关注

    Update html form(entries.php) like this //First you need to pass the 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 // You need to get the id and update condition with where

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮