It is currently Thu Mar 28, 2024 9:53 am


All times are UTC


Forum rules


Please click here to view the forum rules



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: [resolved] Simple PHP/HTML test script not working
PostPosted: Wed Dec 19, 2007 11:22 pm 
Newbie
Newbie

Joined: Wed Dec 19, 2007 11:07 pm
Posts: 7
Hello. This is my first post. I'm very new to PHP (less than a week experience), but I have managed to cobble together a very simple "Hello world" script using information on the internet.

It has worked successfully on two different free-PHP sites, but I can't seem to get it to work with Freehostia. This is actually the first free hosting site I tried, and I only went to others when I couldn't get things working here.

Is there a particular directory I need to be hosting the script in? Is there an .htaccess or other setting I need to be concerned about.

Here is the very simple script, taken from somewhere on the internet...

<?
$message = "I love PHP!";
?>
<html>
<head>
</head>
<body>
<h1>Hello. <? print "$message" ; ?> </h1>
</body>
</html>

Can anyone tell me why I only see the "Hello." portion of this script when I run this on freehostia?

Thank you.


Last edited by JEfromCanada on Sat Dec 22, 2007 12:13 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 7:27 am 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
if you use print that it should be in brackets

Code:
print ($message);


i personaly would recomment using echo "";

Code:
echo $message;


I always find it interesting with how other people code, the way you did that is totaly different to how i would do the same thing, i would do it as follows

Code:
<?php
$message = "I love PHP!";
echo "
<html>
<body>
<h1>" . $message .   "</h1>
</body>
</html>";


The head tags are not needed because there is nothing being put in there, and i echo all the HTML

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 12:12 pm 
Newbie
Newbie

Joined: Wed Dec 19, 2007 11:07 pm
Posts: 7
Josh.Waller wrote:
I always find it interesting with how other people code, the way you did that is totaly different to how i would do the same thing, i would do it as follows

Code:
<?php
$message = "I love PHP!";
echo "
<html>
<body>
<h1>" . $message .   "</h1>
</body>
</html>";
?>


First, Josh, thank you very much for responding, as I am afraid I'm not making much progress on this site, and your response gives me some hope.

Please appreciate that the code I posted is exactly as downloaded from the internet. It is not my creation, since I don't have enough PHP experience to have a "coding style".

And to highlight the point of my original post -- that I can't seem to get the simplest script to run on this site -- your script wouldn't run either on my machine. That's why I'm asking for assistance.

The output of your script was:

" . $message . "

";

Note the regular sized line of text on the line after the <h1> sized text.

Oh, and I added the brackets to the print command, as you suggested. It made no difference to the output of my example, but if you can think of anything else, I would appreciate it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 10:22 pm 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
Are you saving the files as

.htm
.html

or

.php?

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 2:57 am 
Newbie
Newbie

Joined: Wed Dec 19, 2007 11:07 pm
Posts: 7
Josh.Waller wrote:
Are you saving the files as

.htm
.html

or

.php?


They're being saved as .php files.

I'd like to post an http:// link to my file, but am having trouble figuring out the path. When I execute a script from the file manager, the address bar is showing an internal https:// path, rather than the external URL I would normally have expected to see.

If someone tells me how to make my scripts visible from the outside, I'll post a link to the simple one that won't work and see if anyone else gets the proper results.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 5:27 am 
Regular
Regular

Joined: Sun Apr 15, 2007 5:14 pm
Posts: 308
Location: Barrie On Ca
missed something Josh.

Code:
<?php
$message = "I love PHP!";
echo "
<html>
<body>
<h1>" . $message .   "</h1>
</body>
</html>";
?>


the closing php tag.
:oops:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 7:28 am 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
oh yeh. Then an error should display rather than what does.

the path will be


http://username.freehostia.com/foldername/filename.php

The problem could be that your executing it from the file manager. It really sounds like they are just running as HTML so double check that they are .php

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 1:40 pm 
Newbie
Newbie

Joined: Wed Dec 19, 2007 11:07 pm
Posts: 7
Josh.Waller wrote:
oh yeh. Then an error should display rather than what does.

the path will be


http://username.freehostia.com/foldername/filename.php

The problem could be that your executing it from the file manager. It really sounds like they are just running as HTML so double check that they are .php


I saw that you had the missing closing syntax. With or without the missing "?>", I got the same output (as posted). No error message under either scenario -- just missing content.

I also verified the file type several times before posting my problem. I also tried setting the PHP panel to PHP5 and PHP4 - no difference.

As far as trying to execute the script from the address line, the url template you posted is not working for me at all.

I placed my code in the www directory, and used the template http://loginname.freehostia.com/www/testembed.php

I got a server not found message from my browser.

I also created an index.html file just now for purposes of this post. I put the index.html file into the www directory, and used the URLs:

http://loginname.freehostia.com
http://loginname.freehostia.com/index.html
http://loginname.freehostia.com/www
http://loginname.freehostia.com/www/index.html

None of these worked.

I have accounts with several hosting companies. In all cases, doing a traceroute on loginname.hostname.com will give me a valid output. However, when I try this with my freehostia.com account, the traceroute fails.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 2:53 pm 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
Would you mind passing your loginname to me over PM please, or a link to the page.

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 9:15 pm 
Newbie
Newbie

Joined: Wed Dec 19, 2007 11:07 pm
Posts: 7
Josh.Waller wrote:
Would you mind passing your loginname to me over PM please, or a link to the page.


PM sent. Thanks for helping.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 12:15 am 
Newbie
Newbie

Joined: Wed Dec 19, 2007 11:07 pm
Posts: 7
OK, I found the problem... I was getting these reported errors when trying to run my script from the file manager. And I couldn't seem to find a way to run them at all from the browser.

Problem was that I had not defined any subdomains on my account. I guess I just figured that my account name was my subdomain name, and hadn't bothered setting up any subdomains.

When I did that, I was able to access my php forms using the browser, and they worked properly.

Thanks for all who put up with my newbie nonsense.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 23, 2007 10:50 am 
Moderator
Moderator

Joined: Tue Feb 27, 2007 12:18 am
Posts: 521
Excellent news, i forgot you had to do the subdomain stuff to start off with, and i was pretty sure that you where getting the problem because you where opening it through filemanager.

It was not running it through the apache php part of the server so it wasnt compiling and just throwing up the HTML.

If you have any other problems dont be afraid to ask :)

_________________
http://www.mjmclocks.co.uk


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ]  Moderators: Moderators, Support Team

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Hosting | Domains | Servers | Extras | Order | Support | Contacts | FreeHostia © 2011