dou760663 2015-06-17 09:33 采纳率: 100%
浏览 80
已采纳

从HTML文件WAMP运行php脚本

So I have been following this tutorial here

I have installed WAMP and the server is up and running just fine. (As the green light in the taskbar indicates).

In the www folder I have the following 2 files:

        <!DOCTYPE html>
        <html>
        <head>
        <title>First Form</title>
        </head>
        <body>

             <form action="postForm.php" method="post">

             <TextArea 

                name="microBlog" id="microBlog" cols="30" rows=“10">

             </TextArea>  

             <input type="submit">          

            </form>

        </body>
        </html>

and

    <!DOCTYPE html>
    <html>
     <head>
      <title>PHP Test</title>
     </head>
     <body>

        <?php 

            $microBlog = $_POST['microBlog'];          
            echo $microBlog;  

        ?> 

     </body>
    </html> 

However, when I run the html file and input "hello" into the field, clicking the submit button returns a blank screen.

Here is the html screen on open:

enter image description here

and on clicking submit the following is in the address bar:

file:///C:/wamp/www/postForm.php

Any ideas why the blank screen?

Does the PHP (postForm) file require HTML tags or can I get rid of them?

  • 写回答

2条回答 默认 最新

  • dongqing220586 2015-06-17 09:43
    关注

    Open the file via http://localhost/... The reason for the blank screen is: You can open a html-file with the explorer and it will work fine because it will be rendered by the default-web-browser. you need a parser for php-scripts. The Webserver will use this parser if you add the extension .php but if you open the file in the Explorer you don't use the Webserver (in your case apache). If you want to open the file in the explorer set the action-attribute to action="http://localhost/postForm.php" and it will work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?