如何根据基本php文件中按下的按钮重定向到不同的php文件?

时间:2023-01-22 12:54:57

I have a base php file that displays items in a database on an html table. Each row has a remove button. When pressed, it will remove that one item from the database. At the end of the table, there is an add button that once it is pressed will take you to another php file with a form that you can fill out with information to add to the database. I am having two problems. The first is that I am not sure how to determine what remove button is pushed. My second question is how do I move to a different page for the other php file once the add button is clicked? I am not supposed to use AJAX for this. And though I tried using include and isset, I couldn't get them to work properly. Any help, conceptual or code examples would be greatly appreciated.

我有一个基本的php文件,在html表上显示数据库中的项目。每行都有一个删除按钮。按下时,它将从数据库中删除该项。在表的末尾,有一个添加按钮,一旦按下它将带您到另一个php文件,其中包含一个表单,您可以填写要添加到数据库的信息。我有两个问题。首先是我不确定如何确定推送删除按钮。我的第二个问题是,一旦单击添加按钮,如何移动到另一个php文件的不同页面?我不应该为此使用AJAX。虽然我尝试使用include和isset,但我无法让它们正常工作。任何帮助,概念或代码示例将不胜感激。

2 个解决方案

#1


If you can go to other pages, simply create a form with a hidden input field holding the id of the row and have the remove button be a form submit button.

如果您可以转到其他页面,只需创建一个带有隐藏输入字段的表单,其中包含该行的ID,并将删除按钮设置为表单提交按钮。

On the remove button being clicked it will go to the delete php file and redirect back to the table page.

在单击删除按钮时,它将转到删除php文件并重定向回到表页面。

As far as the adding button, instead of using a button just use a link to the add form.

就添加按钮而言,只使用添加表单的链接而不是使用按钮。

If any of this doesn't work because of requirements you haven't mentioned let me know of any restrictions you have.

如果由于您未提及的要求而导致任何此类操作无效,请告诉我您的任何限制。

#2


For your first problem, just make a form for each individual row of data. that way, you will be able to pass by post the relevant id you want to remove.

对于您的第一个问题,只需为每行数据创建一个表单。这样,您就可以通过邮寄方式传递您要删除的相关ID。

Another way would be to create a "button" (not a submit button) and have the relevant onClick="..." script - like redirect to "index?Action=Remove&Id=xxxx"

另一种方法是创建一个“按钮”(不是提交按钮)并具有相关的onClick =“...”脚本 - 比如重定向到“index?Action = Remove&Id = xxxx”

By making different form for each button, you add button will have its own "action" in the form and you'll be allright!

通过为每个按钮创建不同的表单,您添加按钮将在表单中有自己的“动作”,您将是好的!

You either have to generate a new "form" (with proper html) if you need to pass data to your next page. If you only need to redirect depending on which button you press, you can have a onClick="..." event on your button. Make sure not to make a "submit" button :)

如果您需要将数据传递到下一页,您必须生成一个新的“表单”(使用正确的html)。如果您只需要根据按下的按钮进行重定向,则可以在按钮上进行onClick =“...”事件。确保不要“提交”按钮:)

#1


If you can go to other pages, simply create a form with a hidden input field holding the id of the row and have the remove button be a form submit button.

如果您可以转到其他页面,只需创建一个带有隐藏输入字段的表单,其中包含该行的ID,并将删除按钮设置为表单提交按钮。

On the remove button being clicked it will go to the delete php file and redirect back to the table page.

在单击删除按钮时,它将转到删除php文件并重定向回到表页面。

As far as the adding button, instead of using a button just use a link to the add form.

就添加按钮而言,只使用添加表单的链接而不是使用按钮。

If any of this doesn't work because of requirements you haven't mentioned let me know of any restrictions you have.

如果由于您未提及的要求而导致任何此类操作无效,请告诉我您的任何限制。

#2


For your first problem, just make a form for each individual row of data. that way, you will be able to pass by post the relevant id you want to remove.

对于您的第一个问题,只需为每行数据创建一个表单。这样,您就可以通过邮寄方式传递您要删除的相关ID。

Another way would be to create a "button" (not a submit button) and have the relevant onClick="..." script - like redirect to "index?Action=Remove&Id=xxxx"

另一种方法是创建一个“按钮”(不是提交按钮)并具有相关的onClick =“...”脚本 - 比如重定向到“index?Action = Remove&Id = xxxx”

By making different form for each button, you add button will have its own "action" in the form and you'll be allright!

通过为每个按钮创建不同的表单,您添加按钮将在表单中有自己的“动作”,您将是好的!

You either have to generate a new "form" (with proper html) if you need to pass data to your next page. If you only need to redirect depending on which button you press, you can have a onClick="..." event on your button. Make sure not to make a "submit" button :)

如果您需要将数据传递到下一页,您必须生成一个新的“表单”(使用正确的html)。如果您只需要根据按下的按钮进行重定向,则可以在按钮上进行onClick =“...”事件。确保不要“提交”按钮:)