Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've interpreted your question differently to the others.</p> <p>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.</p> <p>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.</p> <p>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.</p> <pre><code>&lt;?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { switch ($_POST['command']) { case 'show_file_1': include 'file_1.php'; break; case 'show_file_2': include 'file_2.php'; break; } exit; } ?&gt; &lt;form method="POST"&gt; &lt;button name="command" value="show_file_1"&gt;Show file 1&lt;/button&gt; &lt;button name="command" value="show_file_2"&gt;Show file 2&lt;/button&gt; &lt;/form&gt; </code></pre> <p>Note: I've included only the relevant HTML and PHP to illustrate the point. Obviously you'd add <code>&lt;html&gt;</code>, <code>&lt;head&gt;</code> and <code>&lt;body&gt;</code> tags, and likely shuffle and modularize the PHP a bit, depending on what you're going to add.</p> <p>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 <code>include</code> to a redirect. That is:</p> <pre><code>include 'file_1.php'; </code></pre> <p>would become:</p> <pre><code>header('Location: http://mysite.com/file_1.php'); </code></pre> <p>It's hard to know what to recommend without knowing the nature of your existing files.</p> <p>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 <code>;</code> error? If I had to guess, I would say check that you're using a <code>:</code> (colon) and not <code>;</code> (semi-colon) at the end of the <code>case 'show_file_1'</code> and <code>case 'show_file_2'</code> lines.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload