我如何在php中实现编辑和删除按钮

时间:2018-08-20 08:42:32

标签: php mysql

这是我的代码

我可以将数据添加到表中

我无法创建删除和修改按钮

我英语不好,但我会尽力了解你的情况。

<?php 
     $cat_id = $conn->real_escape_string($_REQUEST['Cat_id']);
     $Cat_name = $conn->real_escape_string($_REQUEST['Cat_name']);
     if(isset($_REQUEST['save'])){
     $sql = "insert into category_(Cat_id,Cat_name)
             value('".$_REQUEST["Cat_id"]."','".$_REQUEST["Cat_name"]."')";
     $insert_cat = $conn->query($sql);  
}
if($_REQUEST['del']){
$sql1 = "delete from category_ where cat_id ='".$_REQUEST["Cat_id"]."' and cat_name='".$_REQUEST["Cat_name"]."' ";
$delete = $conn->query($sql1);
}   
?>

显示

表单插入数据

<form name="insert" method="post" action="">
 <div class="col-xs-12">
<div class="panel panel-default" style="display: block; visibility: visible; opacity: 1; transform: translateY(0px);" data-widget='{"draggable": "false"}' data-widget-static="">
<div class="panel-heading" >
<h2>เพิ่มหมวดหมู่</h2>
</div>
<div class="panel-body">
<!--  -->
<div class="row" style="margin-bottom: 10px;">  
<label class="col-sm-3" style="padding-top: 7px; margin-left: 150px;">รหัสหมวดหมู่</label>
<div class="col-xs-4"><input name="Cat_id"  class="form-control" required="" type="text" placeholder="กรอกรหัสหมวดหมู่" data-parsley-minlength="6"></div>
</div>
<div class="row" style="margin-bottom: 10px;">
<label class="col-sm-3" style="padding-top: 7px; margin-left: 150px;">ชื่อหมวดหมู่</label>
<div class="col-xs-4"><input name="Cat_name" class="form-control" required="" type="text" placeholder="กรอกชื่อหมวดหมู่" data-parsley-minlength="6"></div>
</div>
<div class="row" style="margin-bottom: 10px;">  
<!-- <button type="button" class="btn btn-default">Default</button> -->
<div class='test'>
<div style='float: left;'>
<button type="reset" name="reset" class="btn btn-default" style="margin-left: 25px;">เคลียร์</button>
</div>
<div style='float: right;'>
<button type="submit" name="save" class="btn btn-success" style="margin-right: 25px;">ยืนยัน</button>
</div>
</div>
</div>
</div>      
</div>      
</div>
</form>

我无法从mycode中删除数据

我想添加一个删除选项,该选项调用另一个表单。我似乎无法使其正常工作。

请帮助我

<div class="col-xs-12">
<div class="panel panel-default" style="display: block; visibility: visible; opacity: 1; transform: translateY(0px);" data-widget='{"draggable": "false"}' data-widget-static="">
<div class="panel-heading">
<h2>รายการหมวดหมู่หนังสือ</h2>
<div class="panel-ctrls" data-action-collapse='{"target": ".panel-body"}' data-actions-container=""><span class="button-icon has-bg"><i class="ti ti-angle-down"></i></span><i class="separator"></i></div>
</div>
<div class="panel-body">
<!--  -->
<table class="table table-bordered" id="example">
<thead>
<tr bgcolor="rgba(0, 162, 158, .6)" >
<th>ลำดับ</th>
<th>รหัสหมวดหมู่</th>
<th>ชื่อหมวดหมู่</th>
<th>ดำเนินการ</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT Cat_id,Cat_name FROM category_";
$result = $conn->query($sql);
if ($result->num_rows > 0) { $i = 0;
while($row = $result->fetch_assoc()) { $i++;
echo "<tr>";
echo "<td>". $i ."</td>";
echo "<td>" . $row["Cat_id"]. "</td>";
echo "<td>" . $row["Cat_name"]. "</td>";
echo '<td align="center">
<button title="แก้ไข" class="btn btn-warning btn-ml">Modify<i class="ti ti-close"></i></button>
<button title="ลบ" class="btn btn-danger btn-ml" id="delete" name="delete" type="submit" >Delete<i ="ti ti-close"></i></button>
</td>';
echo "</tr>";
}
}
$conn->close();
?>
</tbody>
</table>`enter code here`
</div>      
</div>  
</div>
</html>
enter code here

0 个答案:

没有答案