删除数据的顺序相反

时间:2017-11-24 10:09:48

标签: javascript php html css ajax

<!DOCTYPE html>  
 <html>  
      <head>  
           <title></title>  
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
      </head>  
      <body>  
           <br /><br />  
           <div class="container" style="width:700px;">  
               
                <br />  
                <div class="table-responsive">  
                     <div align="right">  
                          
                     </div>  
                     <br />  
                     <div id="employee_table">  
                          <table class="table table-bordered">  
                               <tr>  
                                    <th width="70%"> Name</th>  
                                    <th width="15%">Edit</th>  
                                    <th width="15%">View</th>  
									<th width="15%">Delete</th>  
                               </tr>  
                               <?php  
                               while($row = mysqli_fetch_array($result)) 
                                  								   
                               {  
							   $id=$row['id'];
                               ?>  
                               <tr>  
                                    <td><?php echo $row["employee_name"]; ?></td>  
                                    <td><input type="button" name="edit" value="Edit" id="<?php echo $id; ?>" class="btn btn-info btn-xs edit_data" /></td>  
                                    <td><input type="button" name="view" value="view" id="<?php echo $id; ?>" class="btn btn-info btn-xs view_data" /></td>  
									<td><a href="#delete_data_Modal<?php echo $id;?>"><button type="button" name="add" id="deleteBtn" data-toggle="modal" data-target="#delete_data_Modal" class="btn btn-info btn-xs ">delete</button></a></td>  
									
                               </tr>  
                               <?php  
                               }  
                               ?>  
                          </table>  
                     </div>  
                </div>  
           </div>  
      </body>  
 </html>  
 <div id="dataModal" class="modal fade">  
      <div class="modal-dialog">  
           <div class="modal-content">  
                <div class="modal-header">  
                     <button type="button" class="close" data-dismiss="modal">&times;</button>  
                     <h4 class="modal-title">Employee Details</h4>  
                </div>  
                <div class="modal-body" id="employee_detail">  
                </div>  
                <div class="modal-footer">  
                     
                     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  					 
                </div>  
           </div>  
      </div>  
 </div>  
 <div id="add_data_Modal" class="modal fade">  
      <div class="modal-dialog">  
           <div class="modal-content">  
                <div class="modal-header">  
                     <button type="button" class="close" data-dismiss="modal">&times;</button>  
                     <h4 class="modal-title"></h4>  
                </div>  
                <div class="modal-body">  
                     <form method="post" id="insert_form">  
                          <label>Enter Employee Name</label>  
                          <input type="text" name="name" id="name" class="form-control" />  
                          <br />  
                          <label>Enter Employee Address</label>  
                          <textarea name="address" id="address" class="form-control"></textarea>  
                          <br />  
                          
                          <label>Enter Age</label>  
                          <input type="text" name="age" id="age" class="form-control" />  
                          <br />  
                          <input type="hidden" name="employee_id" id="employee_id" />  
                          <input type="submit" name="insert" id="insert" value="Insert" class="btn btn-success" />  
                     </form>  
                </div>  
                <div class="modal-footer">  
                     <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
                </div>  
           </div>  
      </div>  
 </div> 
<div id="delete_data_Modal" class="modal fade">  
      <div class="modal-dialog">  
           <div class="modal-content">  
                <div class="modal-header">  
                     <button type="button" class="close" data-dismiss="modal">&times;</button>  
                     <h4 class="modal-title"></h4>  
                </div>  
                <div class="modal-body">  
                     <form method="post" >  
				
                         <p>Are You Sure Want to Delete this data?????</p>
                     </form>  
                </div>  
                <div class="modal-footer">  
				<a href="delete.php<?php echo '?id='.$id; ?>" class="btn">Delete</a>
                    <button type="button" class="btn btn-default" data-dismiss="modal">No</button>  
                </div>  
           </div>  
      </div>  
 </div>   

<!---delete.php--->
<?php
require_once('db.php');
 
$get_id=$_GET['id'];

// sql to delete a record
$sql = mysqli_query($conn,"Delete from employee where id = '$get_id' ");

// use exec() because no results are returned
if($sql)
{  
header('location:index.php');
}
else
{
	echo "not";
}
?>
此代码是使用ajax through bootstrap模式框从表中编辑,查看和显示数据,并在提交相应按钮后显示错误消息。现在,编辑,更新和查看数据已成功完成,并且还成功显示错误消息。但是,在删除数据期间,当点击第一个删除按钮时,最后一个数据正在被删除。表格结构和删除代码如上所示。

0 个答案:

没有答案