Ajax implementations delete data from a database

Source: Internet
Author: User

HTML code

<!doctype html>
<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>

<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> name </th>
<th> Password </th>
<th> Sex </th>
<th> Department </th>
<th> class </th>
<th> Telephone </th>
<th> Operations </th> <!--add an action column--
</tr>
<?php


Header (' Content-type:text/html;charset=utf-8 ');


Include_once ("conn/conn.php"); Import Database Control page introduced



$sql = "Select*from user"; Querying the user in the database;

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

$row =mysqli_fetch_array ($R); Types of arrays queried

while ($row =mysqli_fetch_array ($r)) {
/*print_r ($row);
echo "<br>"; * *
/* echo $row ["name"]. " = ". $row [" Mima "]; Query names and passwords can also be queried by keys
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> <!--data from a database loaded with tables--
<td><?php echo $row ["Xibu"]?></td>
<td><?php echo $row ["Banji"]?></td>
<td><?php echo $row ["Tex"]?></td>
&LT;TD style= "color:red;" ><a href= "" onclick= "del (<?php echo $row [" id "]?>);" > Delete </a></td> <!--add a delete onclick implementation in a column jump-


</tr>


<?php
}
?>

<script>
Function del ($id) {

var id= $id;
if (ID) {
$.get ("shanchu.php", {id:id},function (data) {/*get Get data */
if (data=201) {
Alert ("Success");
Window.location.href=window.location.href; /* Refresh */
}else {
Alert ("failure");

}

});
}else {
Alert ("failure");
}
}






</script>

</table>
</body>

PHP Code
<?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 implementations delete data from a database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.