0

This is my Admin Dashboard

I am going to make the trash icon to delete the information row that is display from database. I found that is something wrong with my code that make the information row cannot be delete after click on the trash button.

This is my php file.

<?php
     session_start();
       include'dbconnection.php';
     // checking session is valid for not 
     if (strlen($_SESSION['id']==0)) {
     header('location:logout.php');
   } else{


    // for deleting user
 if(isset($_GET['id']))
    {
 $adminid=$_GET['id'];
  $msg=mysqli_query($con,"DELETE FROM `joblist` WHERE id='$adminid'");
  if($msg)
  {
     echo "<script>alert('Data deleted');</script>";
    }
    }


    ?><!DOCTYPE html>
  <html lang="en">
    <head>
   <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
   <meta name="author" content="Dashboard">
   <meta name="keyword" content="Dashboard, Bootstrap, Admin, Template, Theme, Responsive, Fluid, 
   Retina">

 <title>Admin | Job list</title>
  <link href="assets/css/bootstrap.css" rel="stylesheet">
  <link href="assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
  <link href="assets/css/style.css" rel="stylesheet">
  <link href="assets/css/style-responsive.css" rel="stylesheet">
 </head>

  <body>

 <section id="container" >
  <header class="header black-bg">
          <div class="sidebar-toggle-box">
              <div class="fa fa-bars tooltips" data-placement="right" data-original-title="Toggle 
     Navigation"></div>
          </div>
        <a href="#" class="logo"><b>Admin Dashboard</b></a>
        <div class="nav notify-row" id="top_menu">



            </ul>
        </div>
        <div class="top-menu">
            <ul class="nav pull-right top-menu">
                <li><a class="logout" href="logout.php">Logout</a></li>
            </ul>
        </div>
    </header>
      <aside>
      <div id="sidebar"  class="nav-collapse ">
          <ul class="sidebar-menu" id="nav-accordion">

              <p class="centered"><a href="#"><img src="assets/img/ui-sam.jpg" class="img-circle" 
       width="60"></a></p>
              <h5 class="centered"><?php echo $_SESSION['login'];?></h5>

              <li class="mt">
                  <a href="change-password.php">
                      <i class="fa fa-file"></i>
                      <span>Change Password</span>
                  </a>
              </li>

              <li class="sub-menu">
                  <a href="manage-users.php" >
                      <i class="fa fa-users"></i>
                      <span>Manage Users</span>
                  </a>

              </li>

              <li class="sub-menu">
                  <a href="joblist.php" >
                      <i class="fa fa-users"></i>
                      <span>Job List</span>
                  </a>

              </li>
              <li class="sub-menu">
                  <a href="addjob.php" >
                      <i class="fa fa-users"></i>
                      <span>Update Job</span>
                  </a>

              </li>             

          </ul>
      </div>
  </aside>
  <section id="main-content">
      <section class="wrapper">
        <h3><i class="fa fa-angle-right"></i> Jobs List</h3>
            <div class="row">



              <div class="col-md-12">
                  <div class="content-panel">
                      <table class="table table-striped table-advance table-hover">
                          <h4><i class="fa fa-angle-right"></i> All jobs </h4>
                          <hr>
                          <thead>
                          <tr>
                              <th>No.</th>
                              <th> apader1</th>
                              <th> apader2 Id</th>
                              <th>apader3</th>
                              <th>apader4</th>
                              <th>add. Date</th>
                          </tr>
                          </thead>
                          <tbody>
                          <?php $ret=mysqli_query($con,"select * from joblist");
                          $cnt=1;
                          while($row=mysqli_fetch_array($ret))
                          {?>
                          <tr>
                          <td><?php echo $cnt;?></td>
                              <td><?php echo $row['list1'];?></td>
                              <td><?php echo $row['list2'];?></td>
                              <td><?php echo $row['list3'];?></td>
                              <td><?php echo $row['list4'];?></td> 
                               <td><?php echo $row['post_date'];?></td>
                              <td>

                                 <a href="update-profile.php?uid=<?php echo $row['id'];?>"> 
                                 <button class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i> 
       </button></a>
                                 <a href="joblist.php?id=<?php echo $row['id'];?>"> 
                                 <button class="btn btn-danger btn-xs" onClick="return confirm('Do 
            you really want to delete');"><i class="fa fa-trash-o "></i></button></a>
                              </td>
                          </tr>
                          <?php $cnt=$cnt+1; }?>

                          </tbody>
                      </table>
                  </div>
              </div>
          </div>
    </section>
  </section
         ></section>
        <script src="assets/js/jquery.js"></script>
       <script src="assets/js/bootstrap.min.js"></script>
       <script class="include" type="text/javascript" src="assets/js/jquery.dcjqaccordion.2.7.js"> 
      </script>
    <script src="assets/js/jquery.scrollTo.min.js"></script>
      <script src="assets/js/jquery.nicescroll.js" type="text/javascript"></script>
     <script src="assets/js/common-scripts.js"></script>
        <script>
    $(function(){
        $('select.styled').customSelect();
  });

    </script>

      </body>
   </html>
  <?php } ?>

Please review my code and have a solution on this as i cannot see other solution to make this work.

nur atiqa
  • 33
  • 1
  • 4
  • You can't put an anchor inside a button. – Barmar Mar 05 '20 at 01:48
  • And the `onclick` handler of the button doesn't have any effect on the anchor. – Barmar Mar 05 '20 at 01:48
  • **WARNING**: When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [`bind_param`](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add any data to your query. **DO NOT** use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST`, `$_GET` or data *of any kind* directly into a query, it can be very harmful if someone seeks to exploit your mistake. – tadman Mar 05 '20 at 02:39
  • Note: The [object-oriented interface to `mysqli`](https://www.php.net/manual/en/mysqli.quickstart.connections.php) is significantly less verbose, making code easier to read and audit, and is not easily confused with the obsolete `mysql_query` interface where missing a single `i` can cause trouble. Example: `$db = new mysqli(…)` and `$db->prepare("…")` The procedural interface is an artifact from the PHP 4 era and should not be used in new code. – tadman Mar 05 '20 at 02:40
  • If you're just getting started with PHP and want to build applications, I'd strongly recommend looking at various [development frameworks](https://www.cloudways.com/blog/best-php-frameworks/) to see if you can find one that fits your style and needs. They come in various flavors from lightweight like [Fat-Free Framework](https://fatfreeframework.com/) to far more comprehensive like [Laravel](http://laravel.com/). These give you concrete examples to work from and guidance on how to write your code and organize your project's files. – tadman Mar 05 '20 at 02:40

0 Answers0