我的PHP代码没有执行

时间:2015-04-07 06:33:26

标签: php html

我在执行简单的PHP代码时遇到了一些麻烦。它只是在我的网站中包含一些HTML,我希望保持不变。

这是我希望包含的PHP文件:

<div class = "row2col1">
                <h2><u> Links </u></h2>
                <br/>
                <a class="sidebar" href="aboutus.html">About Us</a>
                <br/>
                <a class="sidebar" href="http://www.yougov.co.uk/">YouGov</a>   
                <br/>
                <a class="sidebar" href="https://www.conservatives.com/">Conservatives</a>  
                <br/>
                <a class="sidebar" href="http://www.labour.org.uk/">Labour</a>  
                <br/>
                <a class="sidebar" href="http://www.libdems.org.uk/">Liberal Democrats</a>  
                <br/>
                <a class="sidebar" href="http://www.snp.org/">SNP</a>
                <br/>   
                <a class="sidebar" href="http://www.bnp.org.uk/">BNP</a>
                <br/>
                <a class="sidebar" href="http://www.ukip.org/">UKIP</a>
                <br/>
                <form>
                    <input type="button" value="Login/Sign Up" onClick="clicked()" />
                </form>                 
            </div>

我已将此保存为sidebar.php。这是网站主页其余部分的代码,包括php include脚本:

    <!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd"
<html>
    <head>
        <title>Poll Analysis</title>
        <link rel="stylesheet" type="text/css" href="style.css" />
        <script>
                function clicked(){
                alert("This is currently under construction. We're sorry");
                }
        </script>
</head>
    <body>
        <div class= "main">
            <div class = "row1">
                <img src="http://i.imgur.com/Jr8K4oz.png" width="100%" height="100%" />
                </hr>
                </br>
            </div>
        </div>
            <div class = "row2">
            <?php include("sidebar.php");?>
                <div class = "row2col2">
                    <h1> ENTER ARTICLE TITLE HERE </h1>
                    <hr/>
                    <br/>                   
                    <p> Enter article here </p>
                    <p> Enter article here </p> 
                    <p> Enter article here </p> 
                    <p> Enter article here </p> 
                    <p> Enter article here </p> 
                    <p> Enter article here </p> 
                    <p> Enter article here </p> 
                    <p> Enter article here </p>                     
                    </div>
            </div>
                <footer>
                    <hr/>
                    <br/>
                    <p> Page hosted by <a href ="http://www.000webhost.com/852668.html"> 000webhost </p></a>
                    <p> &#169; Mark Turner 2015 </p>
                </footer>           
            </body>
</html>         

我最初将其保存为.html文件,但后来我记得你必须将它保存为index.php才能执行PHP脚本。但是,当我更改它时,我在浏览器中得到了这个:

enter image description here

有人可以告诉我我做错了什么(可能是上次真的很蠢!)

提前致谢, 马克特纳:)

2 个答案:

答案 0 :(得分:2)

Php需要一台服务器来运行代码。对于Windows使用wamp服务器。如果你有wamp服务器将你的代码移动到wamp中的www文件夹。

下载网站中的wamp服务器

http://en.kioskea.net/download/download-1318-wamp-server

对于mac下载mamp服务器

https://www.mamp.info/en/

答案 1 :(得分:1)

您必须安装apache服务器才能运行php。我更喜欢Xampp。 要运行:

  1. 您可以从https://www.apachefriends.org/download.html
  2. 下载
  3. 在../ xampp / htdocs /
  4. 下创建一个文件夹
  5. 害怕你的代码../ xampp / htdocs / YourFolder
  6. 打开Xampp控制面板并启动Apache和Mysql
  7. 打开浏览器,然后输入&#34; localhost / YourFolder / index.php&#34; (或&#34; localhost / YourFolder&#34; [当且仅当您的文件是index.php / index.html]时,在地址栏中
相关问题