post - How can I add delete in php code -


if refer code below, trying add delete link inside gridview. , @ same time if click it, want delete line database. please me out.

here's html php code:

<?php session_start(); $loginuser = $_session['result'];  if ($loginuser['position'] != "hr assistant" ) {  }   else{ header("location:hrpage.php");  }  ?> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-   ui.css"> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css"> <script>  $(function() {    $( ".datepicker" ).datepicker({        dateformat: "yy-mm-dd",     mindate: 0 });   });   </script>  <html> <head> <link rel="stylesheet" href="master.css" type="text/css"> </head> <body>     <div class="divpage">         <br>         <div class="divfloatholder">             <div style="height: 50px; width: 98%;margin-left: 5px;border:inset; background:#099dd9">                 <div>                     <div class="textheader">                          <p class="editedp"><label class="labelheader">employee:</label>&nbsp&nbsp<?php echo $loginuser['fullname']?></p>                     </div>                     <div class="textheader">                          <p class="editedp"><label class="labelheader">email:</label>&nbsp&nbsp&nbsp<?php echo $loginuser['email']?></p>                     </div>                     <div style="width:30%; float: right; text-align: right;">                          <p style="margin-top: 3px; margin-bottom: 1px"><a href="">settings</a>|<a href="logout.php">log out</a></p>                     </div>                 </div>                     <div class="textheader">                          <p class="editedp"><label class="labelheader">position:</label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<?php echo $loginuser['position']?></p>                     </div>                     <div class="textheader">                          <p class="editedp"><label class="labelheader">shift:</label>&nbsp&nbsp&nbsp&nbsp<?php echo $loginuser['startofshift']?>-<?php echo $loginuser['endofshift']?></p>                     </div>             </div>             <div class="rightdivpage">                 <form action="insert.php" method="post">                 <div>                     <div style="height: 90px; width: 47.5%; margin-left: 5px; float: left; text-align: left;">                         <p class="editedp"><label>request date:</label>&nbsp&nbsp&nbsp&nbsp<?php                             $currentdate = date("f j, y");                             echo $currentdate."<br/>";                         ?></p>                         <p class="editedp"><label>start date:</label>&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" class="datepicker" name="startdate"></p>                         <p class="editedp"><label>end date:</label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" class="datepicker" name="enddate"></p>                     </div>                     <div style="height: 90px; width: 47.5%;margin-left: 5px; float: right; text-align: left;">                         <p class="editedp"><label>reason:</label>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="reason"></p>                         <p class="editedp"><label>type of leave:</label>&nbsp&nbsp&nbsp&nbsp                              <select class="custom-select" name="typeofleave">                                         <option>select type of leave</option>                                         <option>sick leave</option>                                         <option>vacation leave</option>                                         <option>paid leave</option>                                         <option>unpaid leave</option>                             </select></p>                         <p class="editedp"> <button>submit</button></p>                     </div>                 </div>                 <div style="height:70%;">                     <?php                     $con=mysqli_connect("localhost","root","","leavecalendar");                     // check connection                     if (mysqli_connect_errno())                     {                     echo "failed connect mysql: " . mysqli_connect_error();                     }                      $result = mysqli_query($con,"select * leavedetails username = '$loginuser[username]'");                      echo "<table border='1' class='form-table' width='10%'>                     <tr>                           <th>leave type</th>                           <th>start date</th>                           <th>end date</th>                           <th>reason</th>                           <th>status</th>                     </tr>";                      while($row = mysqli_fetch_array($result))                     {                     echo "<tr>";                     echo "<td>" . $row['typeofleave'] . "</td>";                     echo "<td>" . $row['stardate'] . "</td>";                     echo "<td>" . $row['endate'] . "</td>";                     echo "<td>" . $row['reason'] . "</td>";                     echo "<td>" . $row['status'] . "</td>";                     echo "</tr>";                     }                     echo "</table>";                      mysqli_close($con);                 ?>                 </div>                 <br>                 <input type="submit" name="submit" value="submit">             </div>         </form>             <div style="float:left; width: 23%; height: 88%; border: solid; margin-left: 5px; margin-top:5px;">                 asdsadsad             </div>         </div>     </div>   </body> 

now here's code deletion:

<?php session_start(); $loginuser = $_session['result']; $con=mysqli_connect("localhost","root","","leavecalendar"); // check connection if (mysqli_connect_errno())   {   echo "failed connect mysql: " . mysqli_connect_error();   }  //$myusername=$_post['username'];  //$mypassword=$_post['startdate'];   $sql="delete `leavedetails` username = '$loginuser[username]' , reason =     '$_post[reason]'" echo ($sql);  if (!mysqli_query($con,$sql))    {   die('error: ' . mysqli_error($con));   }  //echo "1 record added";  header("location:login_success.php");   mysqli_close($con); ?> 


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -