When I click a link a simple HTML web form linked to a php file, the browser is downloading the PHP file rather than executuing it in the browser. Any dieas?

Is web server configured to serve PHP? Can you show the code of the html file?

Here's the html code fomr the book "PHP and MySQL Web Development"

<html>
<body>
<form action="processorder.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
  <td width="150">Item</td>
  <td width="15">Quantity</td>
</tr>
<tr>
  <td>Tires</td>
  <td align="center"><input type="text" name="tireqty" size="3"
     maxlength="3"></td>
</tr>
<tr>
  <td>Oil</td>
  <td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td>
</tr>
<tr>
  <td>Spark Plugs</td>
  <td align="center"><input type="text" name="sparkqty" size="3"
     maxlength="3"></td>
</tr>
<tr>
  <td>How did you find Bob's?</td>
  <td><select name="find">
        <option value = "a">I'm a regular customer</option>
        <option value = "b">TV advertising</option>
        <option value = "c">Phone directory</option>
        <option value = "d">Word of mouth</option>
      </select>
  </td>
</tr>
<tr>
  <td colspan="2" align="center"><input type="submit" value="Submit Order"></td>
</tr>
</table>
</form>
</body>
</html>

Do a simple test. Create a PHP file (say test.php) with only the following content and check in the browser what happens when you open it.

<?php
phpinfo();
?>

The phpinfo() function should display all sorts of info about PHP if PHP is installed and configured properly on your server. If not then you have to check the installation.

I have tested this in my environment (Ubuntu 12.10, Apache, Firefox 19.0) and it displays php file normaly.

What happens if you navigate your browser to the php file directly?

It work fine when I point the url streight to the php file. localhost/bail.php -> outputs Hello World

When the same file is called from an html form the browser downloads bail.php to my /home/downloads directory.

A few 'stupid' questions (I am blindly guessing now):

  • if you download the php file, what is the contents of it?
  • have you tried this in different browsers (FF, Chrome, IE)?
  • do you use Google sitemaps plugin?
  • have you been changing the php config?
  • how much memory does php have (see in phpinfo)
  • do you use a .htaccess file

Another ideas:
1. change method to GET and see if it works
2. specify enctype="application/x-www-form-urlencoded" for the form (which is default anyway)

 <form action="processorder.php" method="post" enctype="application/x-www-form-urlencoded">