Ashwini Nemade
Ashwini Nemade

Reputation: 153

get specific value from database and display it in textboxeson another page

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.

Upvotes: 0

Views: 38

Answers (3)

Sanju Kaniyamattam
Sanju Kaniyamattam

Reputation: 505

In the summary page do like this. 
 <?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><a href="editentries.php?id='.$res["id"].'"><input type="button" name="edit" class="btn btn-primary" value="Edit"></a></td>
      <td></td>
    </tr>';
  }
    ?>

In the edit page, get the id from the url and add where condition in the sql query.
$id = $_REQUEST['id'];
  $selectname=mysqli_query($conn,"SELECT * FROM feedetails where id = $id GROUP BY name");

Upvotes: 0

DsRaj
DsRaj

Reputation: 2328

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

Upvotes: 1

webshifu
webshifu

Reputation: 185

Pass the id in the post param same as you passed the type (edit/delete)). From that id you can make the query which will fetch the specific record. Your query should go something like this:

mysqli_query($conn,"SELECT * FROM feedetails where id=".$_POST['id']);

Upvotes: 0

Related Questions