ajax實現刪除資料庫中的資料

來源:互聯網
上載者:User

標籤:電話   html   rom   rip   imu   刪除   lap   width   ice   

html代碼

<!doctype html>
<html >
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<script type="text/javascript" src="js/jquery.js"></script>

<title>Document</title>
</head>

<style type="text/css">
table.imagetable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #999999;
border-collapse: collapse;
}
table.imagetable th {
background:#b5cfd2 url(‘cell-blue.jpg‘);
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
table.imagetable td {
background:#dcddc0 url(‘cell-grey.jpg‘);
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #999999;
}
</style>
<body>
<table class="imagetable">
<tr>
<th>id</th>
<th>姓名</th>
<th>密碼</th>
<th>性別</th>
<th>系部</th>
<th>班級</th>
<th>電話</th>
<th>操作</th> <!-- 添加一個操作列-->
</tr>
<?php


header( ‘Content-Type:text/html;charset=utf-8 ‘);


include_once("conn/conn.php"); //引入匯入資料庫控制頁面



$sql="SELECT*from user"; //查詢資料庫中的user;

$r=mysqli_query($link,$sql);

$row=mysqli_fetch_array($r); //查詢出來的數群組類型

while ($row=mysqli_fetch_array($r)){
/*print_r($row);
echo "<br>";*/
/* echo $row["name"]."=>".$row["mima"]; //查詢姓名和密碼 也可以用鍵來查詢
echo "<br>";*/

?>

<tr>
<td><?php echo $row["id"]?></td>
<td><?php echo $row["name"]?></td>
<td><?php echo $row["mima"]?></td>
<td><?php echo $row["xingbie"]?></td> <!-- 從資料庫中查詢出的資料裝著表格中-->
<td><?php echo $row["xibu"]?></td>
<td><?php echo $row["banji"]?></td>
<td><?php echo $row["tex"]?></td>
<td style="color: red;"><a href="" onclick="del( <?php echo $row["id"]?> );">刪除</a></td> <!-- 在列中添加刪除onclick實現跳轉-->


</tr>


<?php
}
?>

<script>
function del($id) {

var id=$id;
if (id){
$.get("shanchu.php",{id:id},function (data) { /*get擷取資料*/
if (data=201){
alert("成功");
window.location.href=window.location.href; /* 重新整理*/
}else {
alert("失敗");

}

});
}else {
alert("失敗");
}
}






</script>

</table>
</body>
</html>

php代碼
<?php
header( ‘Content-Type:text/html;charset=utf-8 ‘);


include_once("conn/conn.php");

$id=$_GET["id"];
$sql="delete from USER WHERE id=$id";
$r=mysqli_query($link,$sql);
if ($r){
echo "201";
}else{
echo "200";
}

ajax實現刪除資料庫中的資料

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.