Self-processing form error?

I’m trying to write a self-processing form. I bought O’Reilly’s book “Programming PHP” and there’s a section on self-processing forms. I installed MAMP. I copied an example form from the book but it won’t run. I put them in the directory /Applications/MAMP/cgi-bin. It returns this error message:

No webpage was found for the web address: file:///Applications/MAMP/cgi-bin/%3C?php%20echo%20$_SERVER[‘PHP_SELF’]%20?%3E
Error code: ERR_FILE_NOT_FOUND

I tried putting the files into my Public directory, and on the desktop, and got the same error message. This is on a Macintosh.

I think the problem is in the “form action” line, but I don’t know how to fix it.

Here’s the code:

[code]

Temperature Conversion <?php $fahrenheit = $_GET['fahrenheit']; if (is_null($fahrenheit)) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
	Fahrenheit temperature:
	<input type="text" name="fahrenheit" /><br />
	<input type="submit" value="Convert to Celsius!" />
</form>
<?php } else { $celsius = ($fahrenheit - 32) * 5 / 9; printf("%.2fF is %.2fC", $fahrenheit, $celsius); } ?> [/code]

You should place your code into the htdocs directory. I can’t use MAMP because I am using a Windows Machine, therefore, I can’t tell you the exact directory structure, you have to do the digging yourself, there will be folder named “htdocs” in the MAMP installation folder.

htdocs serves as a root folder for your web-server meaning that all files and folders must be placed in the htdocs folder in order to run the scripts properly.

After placing your file into the htdocs folder make sure you have started your web-server and you have to access the file via web-browser to run it properly. You can’t run the scripts just by double clicking on it, doing so will just open it in the default web-browser without doing any PHP processing.

I recommend you to go through the documentation on using MAMP or watch a few videos on Youtube. :slight_smile:

OK, I tried putting the files in htdocs but that returned this error message:

No webpage was found for the web address: file:///Applications/MAMP/htdocs/%3C?php%20echo%20$_SERVER['PHP_SELF']%20?%3E Error code: ERR_FILE_NOT_FOUND

It looks to me like PHP isn’t running. The browsers are reading the PHP code as a URL, not executing it. MAMP says that the Apache server and MySQL server are running, so I assume that PHP is running too. I’ll have to dig into the MAMP documentation.

Yeah I think it’s a good idea.

Make sure the server is online. Just because its loaded doesn’t mean its online. Also make sure you have php installed, along with apache. I’ve never used mamp, so I don’t know what all is included. If its the same thing as wamp, then apache and php should be installed, along with phpmyadmin.

What address are you putting into the web browser? Are you using MAMP or MAMP Pro? I think the default for MAMP is http://localhost:8888 for files inside your htdocs.

Sponsor our Newsletter | Privacy Policy | Terms of Service