由 ADMIN 编辑数据
我是 PHP 新手,正在处理小型本地网页和数据库,该网页和数据库获取用户信息,数据库存储相同的用户信息。如果我使用 ADMIN 登录,它会显示所有数据。我的要求是登录用户是管理员,那么他有权编辑我存储在数据库中的所有用户信息。这是使用 GET 方法来完成的。它将如何运作?
I am new to PHP and working on small local webpage and database that takes user information and database stores the same user information .If i Login with ADMIN it shows all data. My requirement is that the loggined user is an admin, then he has a right to edit all the informtion of the users that i stored in the database.And this is to be done using GET method . How it will be working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是一些示例代码,纯粹是为了演示如何使用 GET 方法表单更新表。该代码没有任何类型的错误检查,并假设您已经知道如何连接到数据库(及其 MySQL)。
假设您已到达邀请您编辑数据的页面,您正在编辑的记录由 URL 上的“id”变量引用,该变量与数据库表中的数字主键相匹配。
因此,这将为您提供一个页面,该页面从表中取出数据,将其显示在带有预填充值的表单中,并在提交时转到如下 URL:
在该页面中,您可以访问变量“key”,通过 $_GET 方法获取“myField1”、“myField2”。
然后您只需要更新该页面中的表格:
请注意:上面的代码不适合直接复制/粘贴,因为它不执行任何错误检查等,它纯粹是一个功能示例(并直接在此处键入,因此我如有错别字请见谅!)
Heres some example code purely to demonstrate how to update a table using a GET method form. The code doesn't have any kind of error checking and assumes you already know how to connect to your database (and that its MySQL).
Assuming you've landed on a page which invites you to edit data, which record you're editing is referenced by an 'id' variable on the URL which matches a numerical primary key in your database table.
So, this will give you a page that takes the data out of your table, displays it in a form with pre-filled values and on submit, will go to a URL like:
In that page, you can access variables 'key', 'myField1', 'myField2' via the $_GET method.
Then you just need to update your table within that page:
PLEASE NOTE: The code above is unsuitable for a straight copy/paste as it doesn't do any error checking etc, its purely a functional example (and typed straight in here so I apologise if there are any typos!).