engineerChris Posted June 1, 2011 Share Posted June 1, 2011 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 Link to comment https://forums.phpfreaks.com/topic/238123-server-script-not-rendered-correctly-by-browser/ Share on other sites More sharing options...
.josh Posted June 1, 2011 Share Posted June 1, 2011 This is not a problem with your browser(s), it's a problem with your server and parsing php. Check to make sure the file's mime-type(s) are setup to properly parse php. Link to comment https://forums.phpfreaks.com/topic/238123-server-script-not-rendered-correctly-by-browser/#findComment-1223605 Share on other sites More sharing options...
monkeytooth Posted June 1, 2011 Share Posted June 1, 2011 Personally to me sounds like something on your hosting server is misconfigured. I see no issue with the above coding you have mentioned, unless theres bits and pieces your failing to bring to light. who's your hosting provider? Link to comment https://forums.phpfreaks.com/topic/238123-server-script-not-rendered-correctly-by-browser/#findComment-1223606 Share on other sites More sharing options...
kenrbnsn Posted June 1, 2011 Share Posted June 1, 2011 If you put PHP script into a HTML file, that file needs to have a ".php" extension (unless your server is set up to process .html files with PHP) Ken Link to comment https://forums.phpfreaks.com/topic/238123-server-script-not-rendered-correctly-by-browser/#findComment-1223614 Share on other sites More sharing options...
wildteen88 Posted June 1, 2011 Share Posted June 1, 2011 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> Make sure that code is placed within a .php file. PHP code will not run within .html files. Link to comment https://forums.phpfreaks.com/topic/238123-server-script-not-rendered-correctly-by-browser/#findComment-1223615 Share on other sites More sharing options...
engineerChris Posted June 1, 2011 Author Share Posted June 1, 2011 Many thanks, Ken - you got it right! I renamed my HTML file to .php, removed some boilerplate at the top generated by Bluefish when I created the page, and it now displays correctly. I even re-enabled the call to the PHP script which generates the select contents, and that works, too! BTW - I already had tried the method of adding an AddTYpe statement to httpd.conf, but it didn't help. I'll look into this some more; if I can get this method working, I'll add my result to this thread. Thanks again, and to all for the prompt replies! Chris Link to comment https://forums.phpfreaks.com/topic/238123-server-script-not-rendered-correctly-by-browser/#findComment-1223631 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.