I have two PHP files that I need to link. How can I link the files together using PHP? The effect I want is to have the user click a button, some information is proccessed on the page, and then the result is displayed in a different page, depending on the button the user clicked.Thanks
I've interpreted your question differently to the others.
我以不同的方式解释你的问题。
It sounds to me like you want to create a page with two buttons on it and execute one of your two existing PHP files, depending on which button was pressed.
听起来,我想要创建一个带有两个按钮的页面,并根据按下的按钮执行两个现有PHP文件中的一个。
If that's right, then here's a simple skeleton to achieve that. In this example, page_1.php and page_2.php are your two existing PHP files.
Note if you're doing a lot of this stuff, you probably want to read up on the MVC (Model-View-Controller) pattern and/or try some of the popular PHP frameworks available. It's beyond the scope of this question, but basically both those things will give you a good foundation for structuring your code so that things stay managable and don't become a mess.
Note: I've included only the relevant HTML and PHP to illustrate the point. Obviously you'd add , and tags, and likely shuffle and modularize the PHP a bit, depending on what you're going to add.
UPDATE: I should also add that if either of your existing PHP files contain forms that POST to themselves, you may want to change the include to a redirect. That is:
It's hard to know what to recommend without knowing the nature of your existing files.
在不知道现有文件的性质的情况下,很难知道推荐什么。
EDIT: I'm responding to the OP's second post this way because I don't have enough reputation to comment. Which line number do you get the unexpected ; error? If I had to guess, I would say check that you're using a : (colon) and not ; (semi-colon) at the end of the case 'show_file_1' and case 'show_file_2' lines.
Then $_POST["foo"] will contain the value of that input in other_file.php.
然后$ _POST [“foo”]将包含other_file.php中该输入的值。
#3
0
In PHP's most basic setup, you can use two independent files: one generates the form, the second handles the response. You can also handle this with one file that checks to see if the form as been posted.
Once you get beyond this level, there are must cleaner ways to build the scripts so that you keep your logic and your interfaces separate, but I'm guessing from the question that you're not there yet.