首先本例基于留言本整理版修改。无刷新删除数据 (PHP)我们使用了jquery.js来实现ajax和dom删除
首先本例基于留言本整理版修改。
我们使用了jquery.js来实现ajax和dom删除
首先加入
代码如下:
给table加个
代码如下:
id="t"
写个js:
代码如下:
<script> <BR>function delItem (id) { <BR>$.get('delete.php?id='+id,null,function (msg) {//ajax请求,请求后执行下面代码 <BR>if ('1'==msg) {//返回1表示成功 <BR>$('#t'+id).remove();//把id为txx 的表格删除 <BR>} else {//否则弹出错误信息 <BR>alert(msg); <BR>} <BR>}); <BR>} <BR></script>
删除链接改成 href="javascript:delItem('')"
delete.php的修改就是把错误语句改成直接输出就行了。
OK完成。
index.tpl :
代码如下:
Welcome:
退出
登录
注册
发表留言
[] 发表于: |
附件: |
修改 删除 |
<script> <BR>function delItem (id) { <BR>$.get('delete.php?id='+id,null,function (msg) { <BR>if ('1'==msg) { <BR>$('#t'+id).remove(); <BR>} else { <BR>alert(msg); <BR>} <BR>}); <BR>} <BR></script>
delete.php :
代码如下:
require('common.php');
// 查询出留言信息
$q = $query->query('select * from gb_content where id='.intval($_GET['id']));
$rs = $query->fetch_array($q);
$error = array();
if ($rs['user_id']!=intval($_SESSION['user_id'])) {// 判断user_id是否相同
$error = '该信息你不能删除,只能删除自己发布的';
}
if (!$error) {
$query->query('delete from gb_content where id='.intval($_GET['id']));//删除语句
if ($rs['user_file']) {//删除附件
@unlink('uploads/'.$rs['user_file']);
}
echo 1;//表示成功
} else {
echo $error;
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
