-1

I'm trying to create a php file with my footer details. I want to include this into the necessary pages. The following is my footer.php

footer.php

<?php
    echo "<footer class="footer">
              <div class="container">
                  <p class="text-muted"><a href="contactus.html">Contact Us</a></p>
                  <p class="text-muted"> Copyright &copy; <span id="yearfooter"> </span>. All rights reserved.</p>
</div>
          </footer>";
?>

This is the line I include into my html file to include this footer.php

<?php include 'footer.php'; ?>

But when uploaded to my website, it is not showing the footer file. This is the very first time I'm trying out PHP. I'm not sure if there is something else I'm supposed to do or where I'm going wrong. Any help is much appreciated!

UPDATE

I still cant get this to work. I've also added a .htaccess file and it still doesnt help.

.htaccess

AddType application/x-httpd-php .html

Update

I've managed to get this working. There was some config issues in the server side. Thanks!

Michelle Ashwini
  • 910
  • 2
  • 13
  • 28
  • 1
    Tell me there's not really a space here ` php` – Funk Forty Niner May 26 '16 at 01:29
  • 1
    You've also got some nested quoting issues – Jeff Puckett May 26 '16 at 01:31
  • @JeffPuckettII Good catch on that. I'll find that dupe now. Edit: Found it and closed as such. – Funk Forty Niner May 26 '16 at 01:31
  • @Fred-ii- There is! Thanks I've removed the space now. Nested quoting issues? – Michelle Ashwini May 26 '16 at 01:32
  • @MichelleAshwini yep... you need to escape those `
    ` (etc) inside double quoted echos, or use single quotes. and you're welcome - http://php.net/manual/en/function.error-reporting.php would have been your friend here. ;-)
    – Funk Forty Niner May 26 '16 at 01:33
  • @MichelleAshwini Personally, I like `
    ` better as it renders proper HTML markup and could prove to be useful down the road for a lot of other things. You'll see ;-) they're a bit more work, but I for one don't mind it.
    – Funk Forty Niner May 26 '16 at 01:36
  • @Fred-ii- If I do `
    `, then do I still wrap the echo in single quotes?
    – Michelle Ashwini May 26 '16 at 01:48
  • @Fred-ii- I tried this and it is not being included into the page i've put the `` – Michelle Ashwini May 26 '16 at 01:50
  • @MichelleAshwini make sure you are running this into a local server or else it will display a blank output – winresh24 May 26 '16 at 02:13
  • 1
    @MichelleAshwini if you're escaping the double quotes with `\"`, then you'll have to do it for every instance inside the echo, not just `class=\"footer\"`. so that includes `class=\"text-muted\"`, `href=\"contactus.html\"`, and `id=\"yearfooter\"` which is more work than my answer, but prettier in rendered output cc @Fred-ii- – Jeff Puckett May 26 '16 at 02:14
  • also, you'll find this MOST helpful for this and future issues: http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – Jeff Puckett May 26 '16 at 02:15

1 Answers1

0

Try wrapping your echo in single quotes:

<?php
    echo '<footer class="footer">
              <div class="container">
                  <p class="text-muted"><a href="contactus.html">Contact Us</a></p>
                  <p class="text-muted"> Copyright &copy;     <span id="yearfooter"> </span>. All rights reserved.     </p>
</div>
          </footer>';
?>

And no space between ? and php

<?php include 'footer.php'; ?>
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
  • 1
    *"Try wrapping your echo in single quotes"* - I wouldn't say "Try" but "You must wrap...". "Try" is fit for the comments section ;-) – Funk Forty Niner May 26 '16 at 01:38
  • @Fred-ii- I *try* to safeguard my pride a little bit with code I haven't *actually* tested with lawyer-like qualifiers such as "try", "it seems as though", and "you might consider", regardless of my confidence, just in case there's some additional issue I didn't spot. But you make a good point that I probably shouldn't post any answer without verifying it first. And I guess I can always retract it, so I should just man up and take ownership. – Jeff Puckett May 26 '16 at 02:08
  • the OP says it didn't work (up there in comments) so I for one don't know what to tell her. – Funk Forty Niner May 26 '16 at 02:09