how to delete a record by clicking a button

how to delete a record by clicking a button

ladanladan Posts: 1Questions: 1Answers: 0
edited September 2018 in Free community support

I created a page with the intention to retrieve a record from a database and also required to delete a record by clicking on delete button. Now i am able to develop the page with retrieved data from my database but I tried to write a code that will enable the page to delete a selected record or tuple but I could not do it. pls, I need your help, the source code is given here below:

<!DOCTYPE html>
<html lang="en-US">
<head>
  <title>viewing chairmens</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="project.css">
  <link rel = "stylesheet" type="text/css" href="W3.css">
</head>
<body>
<div class="header">
  <h1><b>FARMERS LOAN MANAGEMENT SYSTEM</b></h1>
</div>
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <ul class="nav navbar-nav">
      <!-- <li><a href="admin_page.php#" onclick="document.getElementById('id04').style.display='block'">Assign Chairman</a></li>
       --><li><a href="view_signup.php" class="w3-button w3-#800000 w3-large">Assign Chairman</a></li>
      <li class="active" ><a href="view_chairmens.php">View Chairmen</a></li>
      <li><a href="view_members.php" class="w3-button w3-#800000 w3-large">View Association's Members</a></li>
   <li><a href="view_applicant.php" class="w3-button w3-#800000 w3-large">View Loan Applicantions</a></li>
    </ul>
     <ul class="nav navbar-nav navbar-right">
      <li><a href="index.php" class="w3-button w3-#800000 w3-large"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li>
    </ul>
  </div>
</nav>

<div id="section">
<div class="table-responsive">
              <table class="w3-table w3-striped w3-border w3-hoverable w3-bordered">
                <caption style="text-align: center; font-weight: bold; font-family: tahoma; font-size: 18px;">List of Assigned Chairmens</caption>
                <thead>
                  <tr>
                    <th>S/No</th>
                    <th>Username</th>
                    <th>Password</th>
                    <th>Association Name</th>
                 
                  </tr>
                </thead>
                <tbody>
                    <?php
                    include("connection.php");
                      $querry2 = "SELECT * FROM login ORDER BY id";
                      $result2 = $conn->query($querry2);
                      if ($result2->num_rows>0) 
                      {
                        while ($row = $result2->fetch_assoc()) 
                        {

                          echo 
                          '
                          <tr>
                            <td>'.$row["id"].'</td>
                            <td>'.$row["username"].'</td>
                            <td>'.$row["password"].'</td>
                            <td>'.$row["Association_name"].'</td>
                            <td style="font-size:14px; font-weight:bold; "><button class="btn btn-danger">Delete</button></td>
                            
                          </tr>
                          ';  
                        }
                      }
                      else
                      {
                         ?>
                        <script>
                        alert("No Record in this table !!!");
                        </script><?php
                      }
                      ?>
                </tbody>
              </table>
            </div>
      </div>
<br>
<footer><p> Copyright &copy; 2018. All Rights Reserved</p></footer>
</body>
</html>

Answers

  • kthorngrenkthorngren Posts: 5,073Questions: 19Answers: 1,123

    Are you using Datatables? If so please post your Datatables code/

    Kevin

Sign In or Register to comment.