Note that there are some explanatory texts on larger screens.

plurals
  1. POInserting PHP into HTML Results in Commented-Out Code
    primarykey
    data
    text
    <p>I am trying to call a function in another .php file from this one by clicking a button, and I encountered this method elsewhere on the Internet, but I'm not sure if it works. I reduced the PHP code to simply printing something onscreen twice instead of calling another file, to demonstrate what is going wrong:</p> <pre><code>&lt;?php echo "hello"; ?&gt; &lt;?php echo &lt;&lt;&lt;END &lt;html&gt; &lt;body&gt; &lt;button type="button" onclick="handleButton()" id="button1"&gt;PHP Test&lt;/button&gt; &lt;script type="text/javascript"&gt; function handleButton() { document.getElementById("button1").innerHTML = "PHP Test&lt;?php echo 'HELLO';?&gt;"; } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; END; ?&gt; </code></pre> <p>Shouldn't pressing the button print "HELLO" on screen? Instead the HTML source for the button becomes:</p> <pre><code>&lt;button type="button" onclick="handleButton()" id="button1"&gt; PHP Test &lt;!--?php echo HELLO;?--&gt; &lt;/button&gt; </code></pre> <p>And nothing happens when the button is clicked. Since "hello" prints fine, why is the server commenting out the second php echo command?</p> <p>P.S.: I anticipate a lot of comments saying, "Why are you trying to do this in the first place?" I know I can make an HTML form that submits to a php file, but my goal here is to make multiple buttons onscreen, each leading to a different php file. I know that I could also make a form lead to a single php file that looks at which button on this screen was pressed, and calls the appropriate php file, but I'd like to avoid making another php file just to do that, if this can work. So unless I'm missing a more efficient approach, I'd prefer that we just stick to the subject of why the server is commenting out that PHP code. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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