当我按下“提交"按钮时,PHP联系表单将返回PHP代码 [英] PHP contact form returning the PHP code when I press the submit button

查看:65
本文介绍了当我按下“提交"按钮时,PHP联系表单将返回PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的网站创建了联系表格.当我单击提交"按钮时,它只会显示PHP代码,而不是应该显示的消息,就像用户在表单中输入的文本信息一样.

以下是表单的HTML代码:

<html>
    <link href="contact.css" rel="stylesheet" type="text/css" />
    <head>
        <title>Contact Us</title>
    </head>

    <body>
        <form action="contact.php" method="post">
            <div id="ContactForm">
                <fieldset>
                    <h4>Contact Parquest:</h4>

                    <label class="labelone" for="name">Name:</label>
                    <input name="name"/>

                    <label for="email">Email: </label>
                    <input name="email"email"/>

                    <label for="commens">Comments: </label>
                    <textarea name="commens"></textarea>
                </fieldset>
                <fieldset>
                    <input class="btn" type="submit" value="Send Email"/>
                    <input class="btn" type="reset" value="Reset Form"/>
                </fieldset>
        </form>
        </div>
</html>

我无法发布PHP代码,因为尝试时它不会显示,所以下面是屏幕截图:

解决方案

您的代码没有问题..问题出在您的环境上..我猜您不是通过服务器运行html文件..

如果浏览器上的网址如下所示:

file:///c:/path/to/your/file/page.html

然后您正在执行错误 ..为了运行.php脚本,您需要一个Web服务器,如apache或nginx ...的url应该像这样

http://localhost/path/to/file/page.html

然后php文件应会按预期运行..

php文件是解释性脚本语言,因此它需要服务器中的解释器才能运行..如果只是在没有服务器的浏览器中浏览,它将仅在其中输出代码.

I created a contact form for my website. When I click the submit button, it just shows the PHP code instead of the message it is supposed to show, like the text information the user inputs into the form.

Here is the HTML code for the form:

<html>
    <link href="contact.css" rel="stylesheet" type="text/css" />
    <head>
        <title>Contact Us</title>
    </head>

    <body>
        <form action="contact.php" method="post">
            <div id="ContactForm">
                <fieldset>
                    <h4>Contact Parquest:</h4>

                    <label class="labelone" for="name">Name:</label>
                    <input name="name"/>

                    <label for="email">Email: </label>
                    <input name="email"email"/>

                    <label for="commens">Comments: </label>
                    <textarea name="commens"></textarea>
                </fieldset>
                <fieldset>
                    <input class="btn" type="submit" value="Send Email"/>
                    <input class="btn" type="reset" value="Reset Form"/>
                </fieldset>
        </form>
        </div>
</html>

I couldn't post the PHP code, because it just doesn't show when I try, so here's a screenshot:

解决方案

There is no problem to your code.. The problem is on your environment.. I guess you are not running the html file through a server..

If the url on your browser looks like these:

file:///c:/path/to/your/file/page.html

then you are doing it wrong.. in order to run .php scripts, you need a web server like apache or nginx... the url of should be like these

http://localhost/path/to/file/page.html

then the php file should run as expected..

php files are interpreted scripting language and thus it needs an interpreter in the server in order to run.. if it is just browsed in the browser without a server, it will just output the code inside..

这篇关于当我按下“提交"按钮时,PHP联系表单将返回PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆