简体   繁体   English

从HTML文件WAMP运行php脚本

[英]Running php script from HTML file WAMP

So I have been following this tutorial here 所以我一直在这里学习本教程

I have installed WAMP and the server is up and running just fine. 我已经安装了WAMP,并且服务器已启动并正常运行。 (As the green light in the taskbar indicates). (如任务栏中的绿色指示灯所示)。

In the www folder I have the following 2 files: www文件夹中,我有以下2个文件:

        <!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. 但是,当我运行html文件并在字段中输入“ hello”时,单击“提交”按钮将返回空白屏幕。

Here is the html screen on open: 这是打开的html屏幕:

在此处输入图片说明

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? PHP(postForm)文件是否需要HTML标记,或者我可以摆脱它们吗?

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. 通过http:// localhost /打开文件。黑屏的原因是:您可以使用资源管理器打开一个html文件,它可以正常工作,因为它将由default-web-browser呈现。 you need a parser for php-scripts. 您需要一个用于php脚本的解析器。 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). 如果添加扩展名.php,则Web服务器将使用此解析器,但是如果在资源管理器中打开文件,则不会使用Web服务器(在您的情况下为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. 如果要在资源管理器中打开文件,请将action-attribute设置为action="http://localhost/postForm.php" ,它将起作用。

You should use 你应该用

action="http://localhost/postForm.php" 

instead of 代替

 action="postForm.php"

hope this help :) 希望这个帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM