• 技术文章 >php教程 >php手册

    php配合jquery实现增删操作具体实例

    2016-06-13 10:18:29原创473
    后台使用php,前台引用jquery,实现增删操作,代码如下:

    复制代码 代码如下:



    header("Content-type: text/html; charset=utf-8");
    //mysql_connect 建立连接,mysql_close($link)关闭非永久连接,mysql_pconnect 建立永久连接
    //mysql_error返回mysql函数错误信息,mysql_errno返回mysql函数错误号码
    //mysql_set_charset 设置用户端字符集,mysql_select_db 选择连接数据库
    //mysql_query 执行查询,mysql_num_rows返回查询记录条数
    //mysql_affected_rows返回受影响的记录条数,mysql_free_result 释放结果集内存
    //mysql_fetch_row 返回列举阵列记录,mysql_fetch_assoc 返回关联阵列记录
    //mysql_fetch_array 返回关联阵列或数字阵列记录,mysql_fetch_object 返回物件形式记录
    //mysql_fetch_result 取得结果集资料
    //%s 字符串,%c 一个ASCII字符,%d 一个整数,%u 一个符号数,%x 一个十六进制数
    mysql_query("set charaset set utf-8");
    $message=@$_POST["message"];
    $shanchu=@$_POST["shanchu"];
    $top_title="PHP基础练习";
    $con=mysql_connect("localhost","root","");
    //连接数据库
    mysql_set_charset('utf-8',$con);
    mysql_select_db("dbl",$con);
    //定义数据库命令查询
    $sql="select `message` ,`time`,`id` from message order by id desc limit 0,30";
    //执行数据库查询
    $rs=mysql_query($sql,$con);
    $time=date('Y-m-d h:i:s',time());
    //获取条数

    $num_rows=mysql_num_rows($rs);//mysql_num_rows返回查询记录条数
    if (isset($_POST["submits"])) {
    if(!$_POST["message"]==null){
    $queryinsert=sprintf("insert into message (message,time) values('%s','%s')",
    $_POST['message'],$time);
    mysql_query($queryinsert,$con);
    }
    if($_POST["message"]==null){
    echo "";
    }
    header("Location:http://localhost/table.php");
    }

    if(isset($_GET["ClearTd"]) && intval($_GET['ClearTd'])){
    $querydelete="delete from message where id=".$_GET['ClearTd'];
    mysql_query($querydelete,$con);
    header("Location:http://localhost/table.php");
    }
    ?>




    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:php实现memcache缓存示例讲解 下一篇:php函数指定默认值方法的小例子
    千万级数据并发解决方案

    相关文章推荐

    • XMLHTTP刷新远程数据的PHP JS代码演示(支持中文)• PHP常用代码• 第十四节 命名空间 [14]• 初学PHP的18个基础例程• ajax跳转传参
    1/1

    PHP中文网