php表单提交按钮
我对 php 比较陌生。我有以下问题。 假设我有一个页面,
- 其中的表单有两个字段 x、y 和两个按钮:提交和清除;
- 一个表格,用两个按钮显示 x、y 的数据库记录,
当我在表单字段中输入值并按下按钮时编辑和删除,提交将数据插入数据库中;数据如下表所示;
当我在表格上按编辑时,表单将填充所选记录中的数据。现在我想提交更新记录,而不仅仅是插入新记录。
我应该如何进行?
谢谢!!!
朱塞佩
I am relatively new to php. I have the following problem.
Suppose I have a page with
- a form with two fields x, y and two buttons: submit and clear;
- a table that shows the db records for x, y with two buttons, edit and delete
when I enter values in the form fields and press button, submit inserts the data in the db; data is then shown in the table below;
when I press edit on the table, the form is populated with the data from the selected record. Now I want submit to update the record and not just insert a new one.
How should I proceed?
Thanks!!!
Giuseppe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在表单中添加一些隐藏字段来区分更新和插入。
一个好的方法是,例如,将主键 has field
放在 PHP 代码上,您可以
对插入表单执行类似的操作,只是不要放置隐藏输入或将值设置为 0
you should add some hidden field in your form to differentiate the updates and insert.
A good way to do that is for example to put your primary key has field
after on the PHP code you can do something like this
for the insert form just don't put the hidden input or make the value being 0
首先,您应该将当前编辑的 id 存储在隐藏字段或查询字符串之类的地方,一旦完成,您应该使用
update
语句来更新记录,而不是插入新记录,例如:您需要显示您的代码才能获得准确的答案。
First of you should be storing id of the current edit somewhere like hidden field or query string, once you have done that, you should use the
update
statement to update the record rather than inserting new one something like:You need to show your code for getting accurate answer.