I am trying to develop a browser interface for an embedded system. The code written so far consists of one HTML page and one PHP script. The HTML page creates a form containing a select widget and a submit button. When the submit button is pressed, the selected item is posted to the PHP script for processing. The PHP script does a MySQL query using the form data and generates HTML to display the query result in a table, which displays in a new Web page. All of this works fine. However...
I need to change the HTML page to create the select widget choices using a the result of a query run when the HTML page gets displayed. I created a PHP script to do this, and included it in my HTML page in this manner:
<form action="procSomeForm.php" method="post">
<?php
include "genSelectList.php";
?>
<input class="main" type="submit" name="submit[view]" value="View" style="width:70px"/>
</form>
When I tried this, the select didn't appear. I tried moving the <select> </select> out of the PHP script and placing them around the "include". The select now displayed but with no contents. After many failed attempts to resolve any errors in the script, I began to suspect that the browser was ignoring the include directive. I then reduced the problem to this trivial code:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
include "tmp.php";
echo "<p>This message brought to you by PHP!</p>";
?>
</body>
</html>
The PHP script looks like this:
<?php
echo "<p>Hello from tmp.php!</p>";
?>
My Web browser rendered the result as:
This message brought to you by PHP!
";?>
The "hello" message in tmp.php wasn't displayed, and the the browser printed the last few characters of the embedded PHP statement as if they were simple text!
I have tried this same experiment on two PCs with the same result. My development PC runs Debian 6.0 (Squeeze) in VMWare on top of WinXP; I access the Web pages locally from within VMWare using IceWeasel. My embedded PC also runs Debian 6.0; I access the Web pages from my WinXP box using Firefox. Interestingly, when I use IE8 to call up the trivial page from the embedded PC, it displays a blank page!
Sorry for the long-winded setup to the problem, but I wanted to point out that generating a separate HTML page from a PHP script works; it appears that the issue is with putting PHP statements in an HTML page.
Any help will be greatly appreciated - thanks in advance!
Chris