1

I purchased a host and domain from godaddy and I'm using Cpanel on godaddy for my website. On cpanel, I have added all of my html files with javascript and css on them, and separate javascript and css files as well. However, whenever I add php code, the php does not run. I tried testing simple code such as

    <?php
     echo "My first PHP script!";
    ?>

to check, however, "My first PHP script!" does not display on my webpage. Everything else on the webpage using html, javascript, and css works perfectly. Therefore, I am wondering if there is anything else I need to include on the page such any php source code, or is there anything I need to download first before running the code?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Nilim
  • 65
  • 1
  • 6
  • 4
    Is your code saved in a `.php` file or in a `.html` file? – R T Nov 19 '15 at 04:30
  • usually the hosting providers have a help option (live chat even) to help you with your problem, as they can see your structure etc – davejal Nov 19 '15 at 04:33
  • My code is saved as a .html file and this didn't affect the JavaScript within the file so will it affect the php? If I make a separate file with the php code, how do I tie it in with the main code? – Nilim Nov 19 '15 at 07:11
  • PHP code runs in a `.php` extension file, while it is enclosed between the PHP syntax tags (``). If you change your file format from `.html` to `.php`, then your code will work. It won't affect your html, css and javascript. You will find an example in the PHP manual: http://php.net/manual/en/tutorial.firstpage.php – R T Nov 19 '15 at 07:38

1 Answers1

4

As I mentioned in the above comment, make sure that your php code is saved in a .php file and not in a .html file. Also, add your PHP code into the /public_html folder on your server. PHP comes by default with all GoDaddy packages. You don't need to include or install anything.

If it still does not work contact customer service. I found them very helpful whenever I had trouble with my hosting account.

R T
  • 1,038
  • 9
  • 17
  • Should I create a separate file with the PHP part of the code? If so, how do I tie this in with the main code? Thank you for your help. – Nilim Nov 19 '15 at 07:13
  • You don't need to create a separate file. If you change your file format from `.html` to `.php`, then your code will work. **It won't affect your html, css and javascript.** You will find an example in the PHP manual [here](http://php.net/manual/en/tutorial.firstpage.php). – R T Nov 19 '15 at 07:41
  • Did the change work? – R T Nov 20 '15 at 00:59
  • Yes, the change worked. I did exactly what you suggested and it worked right away. Thank you so much! – Nilim Nov 20 '15 at 03:02