濮阳杆衣贸易有限公司

主頁 > 知識庫 > Ajax+PHP實現的刪除數據功能示例

Ajax+PHP實現的刪除數據功能示例

熱門標簽:安陽自動外呼系統價格是多少 銀川ai電話機器人 地圖標注風向標 臨沂智能電銷機器人軟件 芒果電銷機器人 十堰ai電話機器人效果怎么樣 電梯外呼線路板維修視頻 上海公司外呼系統線路 浙江外呼電話系統軟件

本文實例講述了Ajax+PHP實現的刪除數據功能。分享給大家供大家參考,具體如下:

一 代碼

conn.php:

?php
  $conn = mysql_connect("localhost", "root", " ") or die("連接數據庫服務器失??!".mysql_error()); //連接MySQL服務器
  mysql_select_db("db_database27",$conn); //選擇數據庫db_database27
  mysql_query("set names utf8"); //設置數據庫編碼格式utf8
?>

del.php:

?php
  include_once("conn/conn.php");//包含數據庫連接文件
    $id=$_GET['id'];//把傳過來的參數值賦給變量$i
    $sql=mysql_query("delete from tb_demo02 where id=".$id);//根據參數值執(zhí)行相應的刪除操作
    if($sql){//如果操作的返回值為true
     $reback=1;//把變量$reback的值設為1
    }else{
     $reback=0;//否則變量$reback的值設為0
    }
    echo $reback;//輸出變量$reback的值
?>

index.js:

function del(id){
    var xml;
    if(window.ActiveXObject){//如果是瀏覽器支持ActiveXObjext則創(chuàng)建ActiveXObject對象
     xml=new ActiveXObject('Microsoft.XMLHTTP');
    }else if(window.XMLHttpRequest){//如果瀏覽器支持XMLHttpRequest對象則創(chuàng)建XMLHttpRequest對象
     xml=new XMLHttpRequest();
    }
    xml.open("GET","del.php?id="+id,true);//使用GET方法調用del.php并傳遞參數的值
    xml.onreadystatechange=function(){//當服務器準備就緒執(zhí)行回調函數
     if(xml.readystate==4  xml.status==200){//如果服務器已經傳回信息并未發(fā)生錯誤
        var msg=xml.responseText;//把服務器傳回的值賦給變量msg
        if(msg==1){//如果服務器傳回的值為1則提示刪除成功
         alert("刪除成功!");
      location.reload();
        }else{//否則提示刪除失敗
         alert("刪除失?。?);
         return false;
        }
   }
    }
    xml.send(null);//不發(fā)送任何數據,因為數據已經使用請求URL通過GET方法發(fā)送
}

index.php:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>分組統計/title>
link rel="stylesheet" type="text/css" href="mystyle.css" rel="external nofollow" >
/head>
body>
script type="text/javascript" src="index.js">/script>
center>
!--banner-->
table width="798" border="0" cellpadding="0" cellspacing="0">
  tr>
      td height="112" background="images/banner.jpg">/td>
  /tr>
/table>
?php
include_once("conn/conn.php");
?>
table width="780" border="0" cellpadding="0" cellspacing="0">
form name="form1" id="form1" method="post" action="deletes.php">
 tr>
     td height="20" width="5%" class="top">nbsp;/td>
  td width="5%" class="top">id/td>
  td width="30%" class="top">書名/td>
  td width="10%" class="top">價格/td>
  td width="20%" class="top">出版時間/td>
  td width="10%" class="top">類別/td>
    td width="10%" class="top">操作/td>
 /tr>
?php
    $sqlstr1 = "select * from tb_demo02 order by id";//按id的升序查詢表tb_demo02的數據
    $result = mysql_query($sqlstr1,$conn);//執(zhí)行查詢語句
    while ($rows = mysql_fetch_array($result)){//循環(huán)輸出查詢結果
?>
 tr>
  td height="25" align="center" class="m_td">
    input type=checkbox name="chk[]" id="chk" value=".$rows['id'].">
    /td>
    td height="25" align="center" class="m_td">?php echo $rows['id'];?>/td>
    td height="25" align="center" class="m_td">?php echo $rows['bookname'];?>/td>
  td height="25" align="center" class="m_td">?php echo $rows['price'];?>/td>
    td height="25" align="center" class="m_td">?php echo $rows['f_time'];?>/td>
    td height="25" align="center" class="m_td">?php echo $rows['type'];?>/td>
    td class="m_td">a href="#" rel="external nofollow" onClick="del(?php echo $rows['id'];?>)">刪除/a>/td>
 /tr>
?php
    }
?>
tr>
    td height="25" colspan="7" class="m_td" align="left">nbsp;nbsp;/td>
/tr>
/form>
/table>
!--show-->
 table width="798" border="0" cellpadding="0" cellspacing="0">
  tr>
   td height="48" background="images/bottom.jpg">nbsp;/td>
  /tr>
/table>
/center>
/body>
/html>

二 運行結果

更多關于PHP相關內容感興趣的讀者可查看本站專題:《PHP+ajax技巧與應用小結》、《PHP網絡編程技巧總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》

希望本文所述對大家PHP程序設計有所幫助。

您可能感興趣的文章:
  • PHP+Ajax檢測用戶名或郵件注冊時是否已經存在實例教程
  • PHP+AJAX實現無刷新注冊(帶用戶名實時檢測)
  • php注冊系統和使用Xajax即時驗證用戶名是否被占用
  • PHP+Ajax異步通訊實現用戶名郵箱驗證是否已注冊( 2種方法實現)
  • jQuery ajax+PHP實現的級聯下拉列表框功能示例
  • Ajax+PHP實現的分類列表框功能示例
  • Ajax+PHP實現的模擬進度條功能示例
  • PHP+Ajax實現的檢測用戶名功能簡單示例

標簽:吐魯番 徐州 武威 常州 遂寧 荊門 遵義 寧夏

巨人網絡通訊聲明:本文標題《Ajax+PHP實現的刪除數據功能示例》,本文關鍵詞  Ajax+PHP,實現,的,刪除,數據,;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Ajax+PHP實現的刪除數據功能示例》相關的同類信息!
  • 本頁收集關于Ajax+PHP實現的刪除數據功能示例的相關信息資訊供網民參考!
  • 推薦文章
    怀仁县| 黄大仙区| 思茅市| 进贤县| 绵竹市| 鄂托克前旗| 花垣县| 镇坪县| 微博| 关岭| 天气| 蓝田县| 蓬安县| 安化县| 庄浪县| 卢氏县| 分宜县| 竹北市| 漯河市| 林西县| 峡江县| 阜新| 双城市| 寻乌县| 鄂尔多斯市| 阿合奇县| 法库县| 当阳市| 砚山县| 卓尼县| 赤城县| 伊通| 清涧县| 墨脱县| 夹江县| 交城县| 贵定县| 随州市| 唐山市| 渝中区| 乐都县|