0

I'm having a bit of trouble getting my simple PHP code to execute. All it does is include some HTML into my website that I wish to remain constant.

Here is the PHP file I wish to include:

<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>

I have saved this as sidebar.php. This is the code for the rest of the website homepage including the php include script:

    <!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>         

I originally saved this as a .html file, but then I remembered that you have to save it as index.php to get the PHP script to execute. However, when I changed it, I got this in my browser:

enter image description here

Can somebody please tell me what I'm doing wrong (it's probably something really stupid like last time!)

Thanks in advance, Mark Turner :)

  • did you setup your site locally? – Keep Coding Apr 07 '15 at 06:34
  • something like: `localhost/mysite/abc.php` – Keep Coding Apr 07 '15 at 06:34
  • @Testing It's not on a server as of yet, this is all on my desktop. I FTP it to my 000webhost account, rather than hosting it locally. Is this a problem? – Mark Turner Apr 07 '15 at 06:36
  • Ofcourse in order to test the site on locally you should setup some development environment in order to get this done locally since you are locally checkering this. – Keep Coding Apr 07 '15 at 06:40
  • @MarkTurner create a new file in public_html directory name it **test.php** and put **** and then open this file in your browser, if you still see this as text..then You server does not support php – Amit Verma Apr 07 '15 at 06:57

2 Answers2

2

Php need one server to run code.For windows use wamp server.If you have wamp server move your code to www folder in wamp.

Download wamp server in the site

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

For mac download mamp server

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

user3386779
  • 6,883
  • 20
  • 66
  • 134
1

You must install apache server to run php. I prefer Xampp. To run :

  1. You can download it from https://www.apachefriends.org/download.html
  2. Creat a folder under ../xampp/htdocs/
  3. pest your code ../xampp/htdocs/YourFolder
  4. Turn On Xampp Control Panel And Start Apache and Mysql
  5. Open a browser and then type "localhost/YourFolder/index.php" (or "localhost/YourFolder" [if and only if your file is index.php/index.html]) in the Address bar
Pradeep Kumar
  • 4,065
  • 2
  • 33
  • 40
Md. Mahmud Hasan
  • 1,033
  • 1
  • 7
  • 24