比如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混写到一起的。你在循环数组的时候就可以用数组下标当序号然后删除就想你那样写
删除你说找不到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混写到一起的。你在循环数组的时候就可以用数组下标当序号然后删除就想你那样写
删除你说找不到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'],导致一直出错。
希望对有同样困扰的人有帮助。
再次谢谢耐心回答问题的人。

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool