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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器