dpfw3607 2014-03-22 02:28
浏览 45

PHP脚本将不会执行,而是显示PHP脚本

First of all, I’m new to web dev, and I’ve also never used PHP before, so please bear with me and my ignorance.

I’m working on a website, and part of it has an HTML form used to send an email. After some Google searching, I found that a simple PHP script would be the easiest way to do it.

Here’s what I have in my HTML file:

<form method="post" name="myemailform" action="form-to-email.php">
    <fieldset>
        <legend>Contact us</legend>
        <div>
            <label for="name">Name: </label>
            <input name="name" id="name">
        </div>
        <div>
            <label for="email">Email: </label>
            <input name="email" id="email">
        </div>
        <div>
            <label for="message">Message: </label>
            <textarea rows="10" cols="40" name="message" id="message"></textarea>
            <input type="submit" value="Send Email" /> 
        </div>
    </fieldset>
</form>

I’m testing the file locally and for some reason, when I click the submit button, instead of running the script, a new tab opens up displaying the contents of the .php file in its entirety.

Can anybody please explain to me why this is happening, and what can I do to fix it? Any help would be appreciated!

Edit: Thanks guys! I didn’t know I needed a local server, and I didn’t know that PHP was one of those things I’d need to install. This is really awkward.... Well now I know! Thanks!

  • 写回答

5条回答 默认 最新

  • douman9420 2014-03-22 02:32
    关注

    The only way the PHP would run is if you were viewing the whole thing on a webserver.

    If this is a local installation, using XAMPP might be the way to go. This is a bundle including Apache (the web server), MySQL (the database system) and PHP, the dynamic programming language.

    If you are directly viewing any PHP script in your browser, it will display the raw PHP code. If you want the actual result to come up, you will need to have a webserver, like the XAMPP bundle (link above).

    Also, if you are using Mac, MAMP is an alternative.

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?