Browser ask me to download php file

2020-02-01 16:52发布

I am a new guy in web programming who still learning new stuff.

I am creating a web form that consist of one INPUT. I connected the form in the HTML file to the php file. I am using a localhost MAMP that I recently installed on my MacBook.

The Problem : When I open the HTML file on a webpage and type something on the input box and hit submit, the browser ask me to download the php file rather processing it.

I don’t think the problem is related to mysql or apache since when I run the MAMP it give me green signs next to the apache and mysql.

Do anyone know how I can fix this problem and the let the php file open and transfer inputs to the database?

4条回答
混吃等死
2楼-- · 2020-02-01 17:21

Did you checked out http://www.mamp.info/en/documentation/faq.html#q8 ?

Maybe you didn't put your site into the folder "htdocs"? PHP won't be parsed unless it is located in that folder or a subfolder.

That would explain the fact that your browser downloads the php file instead of getting the parsed php from apache.

查看更多
做个烂人
3楼-- · 2020-02-01 17:26

You'll want to make sure that Apache has been told that .php files should be treated as PHP scripts. That means one of the following:

LoadModule php5_module        modules/libphp5.so    # on windows, this'd be a .dll instead
AddHandler php5-script php 

and/or

AddType application/x-httpd-php php

in your httpd.conf file.

查看更多
淡お忘
4楼-- · 2020-02-01 17:27

open your file from virtual web-server, not filesystem.
you have to type something like

http://localhost/form.html

in your browser's address bar

查看更多
手持菜刀,她持情操
5楼-- · 2020-02-01 17:32

This error is not only about php but general. The file that the browser suggets to down load is simply the script name, php or not.

查看更多
登录 后发表回答