小女子求教,如何在点击php网页里table中的某记录时,删除数据库中相应记录?
比如php编写的网页中table类似于:
序号 姓名 性别 删除 编辑
1 张三 男 删除 编辑
2 李四 女 删除 编辑
其中,序号、姓名、性别等都是直接从数据库读出来的。
如何做到,在点击序号为1的“删除”时,从数据库中删除序号为1的整条记录?
(删除是href格式的,链接到处理页面。)
想通过点击“删除”时获取序号,然后通过表单POST传递给处理页面,
由处理页面对数据库进行操作。
但是不知道如何获取这个序号啊~~~~~~~~~~
谢谢大神啦
回复讨论(解决方案)
这个得用js获取序号然后赋值到表单当中一个字段里通过post进行操作。
如果就是一个删除完全可以通过Ajax来实现这样就避免提交表单时整个页面都刷新
这个得用js获取序号然后赋值到表单当中一个字段里通过post进行操作。
如果就是一个删除完全可以通过Ajax来实现这样就避免提交表单时整个页面都刷新
不单单是删除,类似的还有“编辑”,也是页面跳转,在新的页面中做处理。
请问,这个js获取序号怎么实现啊,还有赋值到表单中一个字段……
尝试了好多都不对……
比如以下的,提示找不到row
<a href = "delete.php ? id = ' ".$row['id']. " ' ">删除</a>
找不到row?
序号 姓名 性别 删除 编辑
1 张三 男 删除 编辑
2 李四 女 删除 编辑
那?些??你是如何?出的??出的代???看看
找不到row?
序号 姓名 性别 删除 编辑
1 张三 男 删除 编辑
2 李四 女 删除 编辑
那?些??你是如何?出的??出的代???看看
通过 $sqklink,
$sql="select * from users ",
$mysql_query()来读取的~~~~
关键是这个row它好像识别不了啊 。。。
http://blog.csdn.net/MoreWindows/article/details/7102362
这篇文章能够参考,就是通过处理页面获取Id序号来处理,
但是依旧不知道怎么获取这个id 啊。。。。
这个得用js获取序号然后赋值到表单当中一个字段里通过post进行操作。
如果就是一个删除完全可以通过Ajax来实现这样就避免提交表单时整个页面都刷新
不单单是删除,类似的还有“编辑”,也是页面跳转,在新的页面中做处理。
请问,这个js获取序号怎么实现啊,还有赋值到表单中一个字段……
尝试了好多都不对……
比如以下的,提示找不到row
<a href = "delete.php ? id = ' ".$row['id']. " ' ">删除</a>
你的 程序是不是php和html混写到一起的。你在循环数组的时候就可以用数组下标当序号然后删除就想你那样写
<a href = "delete.php ? id = ' ".$row['id']. " ' ">删除</a>你说找不到row什么意思啊。如果有报错把它完整的粘贴出来
<?php// 执行 SQL$sql="select * from users ";// 执行查询$result = mysql_query($sql);// 结果// 参见 mysql_result(), mysql_fetch_array(), mysql_fetch_row() 等。while ($row = mysql_fetch_assoc($result)) { echo $row['序号']; echo $row['姓名']; echo $row['性别'];echo '<a href ="delete.php?id = '.$row['序号']. ' " >删除</a>';}// 释放关联结果集的资源// 在脚本结束的时候会自动进行mysql_free_result($result);?>
把数据库的字段替换一下,里面的 序号 姓名 性别
?了一?例子,看看。
<?php$conn=@mysql_connect('dbhost','dbusername','dbpassword') or die(mysql_error());mysql_select_db('dbname',$conn) or die(mysql_error());$sqlstr = "select * from users";$query = mysql_query($sqlstr) or die(mysql_error());while($thread=mysql_fetch_assoc($query)){ $result[] = $thread;}?><table><tr><td>序?</td><td>姓名</td><td>性?</td><td>?除</td><td>??</td></tr><?phpforeach($result as $row){?> <tr> <td><?php echo $row['id'] ?></td> <td><?php echo $row['name'] ?></td> <td><?php echo $row['gender'] ?></td> <td><a href="del.php?id=<?php echo $row['id'] ?>">?除</a></td> <td><a href="mod.php?id=<?php echo $row['id'] ?>">??</a></td></tr><?php}?></table>
这个得用js获取序号然后赋值到表单当中一个字段里通过post进行操作。
如果就是一个删除完全可以通过Ajax来实现这样就避免提交表单时整个页面都刷新
不单单是删除,类似的还有“编辑”,也是页面跳转,在新的页面中做处理。
请问,这个js获取序号怎么实现啊,还有赋值到表单中一个字段……
尝试了好多都不对……
比如以下的,提示找不到row
<a href = "delete.php ? id = ' ".$row['id']. " ' ">删除</a>
你的 程序是不是php和html混写到一起的。你在循环数组的时候就可以用数组下标当序号然后删除就想你那样写
<a href = "delete.php ? id = ' ".$row['id']. " ' ">删除</a>你说找不到row什么意思啊。如果有报错把它完整的粘贴出来
谢谢你哈,热心人。
(原谅我不能直接贴代码,因为编程的机子无法联网……我只能尽量描述,谢谢你的耐心)
是把php和html混合在一起写的。
目前有两个网页,users.php和delete.php
其中,user.php实现了用table显示各个用户的信息,包括序号,姓名等,每条用户记录后都跟一个“删除”。实现如下:
这样就通过POST提交到href后边的delete.php了吧?
打算通过delete.php实现用这个id检索到数据库中的相应记录,然后删除:
$sql="delete * from users where id =' ". $_POST['id']. " ' ";
但是,出错提示是:POST['id']无法识别这个id,说是无效检索名。
不知道哪里出错了~~·
你这个虽然有form表单在外面。但不是post提交就是URL提交(通过地址栏提交的)所以你这句话
$sql="delete * from users where id =' ". $_POST['id']. " ' ";应该这样写
$sql="delete * from users where id =' ". $_GET['id']. " ' ";
但是,出错提示是:POST['id']无法识别这个id,说是无效检索名。这句话是不是在delete.php报出的啊?
如果你的user.php页面写不好可以参考8楼的
但是,出错提示是:POST['id']无法识别这个id,说是无效检索名。这句话是不是在delete.php报出的啊?
如果你的user.php页面写不好可以参考8楼的
对,是在delete.php中出错了
提示:Undefined index id in delete.php on line 4
我先去试试你们给的建议,谢谢你~~~
<a href="delete.php?id=<?php echo $row['id'] ?>">删除</a>
1、去掉 url 中的多余空格和引号
2、取值用 $_GET['id'],而不是 $_POST['id']
3、如果你确实想用 post 方式。那可以使用 ajax
把数据库的字段替换一下,里面的 序号 姓名 性别
?了一?例子,看看。
<?php<?php}?></table>
你这个虽然有form表单在外面。但不是post提交就是URL提交(通过地址栏提交的)所以你这句话
$sql="delete * from users where id =' ". $_POST['id']. " ' ";应该这样写
$sql="delete * from users where id =' ". $_GET['id']. " ' ";
<a href="delete.php?id=<?php echo $row['id'] ?>">删除</a>
1、去掉 url 中的多余空格和引号
2、取值用 $_GET['id'],而不是 $_POST['id']
3、如果你确实想用 post 方式。那可以使用 ajax
谢谢各位的耐心回复,在你们的帮助下问题已解决,小菜鸟很感激。o(∩_∩)o
其中,7,8,12,15楼的参考价值最大
<a href="delete.php?id=<?php echo $row['id'] ?>">删除</a>
这段代码是对的,为了获取当前行的id,关键是在处理页中一定要用 $_GET['id'],而且id的i是小写,
我把这个id与数据库字段Id搞混了,所以写成了 $_GET['Id'],导致一直出错。
希望对有同样困扰的人有帮助。
再次谢谢耐心回答问题的人。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

An official introduction to the non-blocking feature of ReactPHP in-depth interpretation of ReactPHP's non-blocking feature has aroused many developers' questions: "ReactPHPisnon-blockingbydefault...
