Jump to content

mega noob question, 1st php program


meemoe_uk
Go to solution Solved by meemoe_uk,

Recommended Posts

hi all, total beginner here, Just trying to get my first php programs to work

 

<?php

echo " hello world " ;

?>

 

doesn't print anything....

 

 

***

 

<html>
 <head>
 </head>
 <body>
 
  <?php

    print "<h1> hello </h1>";
    // abcdedfg

  ?>

 </body>
</html>

 

***

 

is suppose to print " hello "

what i get is "   hello "; // abcdedfg ?>  "

if i don't use the <h1>, it prints nothing.

 

 

i run these scripts by opening them with a right mouse clcik on their windows file icon, and opening with firefox.

maybe my settings aren't set right

 

help plz

Link to comment
Share on other sites

php is a web server-side scripting language. you need to request the page using a url on a web server. you can install a web server on your local computer to learn and develop php code. there are all-in-one AMP (Apache, Mysql, Php) packages you can find and install to do this. Xampp from apachefriends.org is probably the most common package.

Link to comment
Share on other sites

It sounds like you maybe loading your .php files directly into your web browser (ie the url address starts with file://C:/User/xxx....) This is the incorrect way for testing your php code.

 

 

I have apache and mysql servers running on xampp v3.2.1,

All your web site files needs to be saved in XAMPP's htdocs folder (eg C:\XAMPP\htdocs). You then proceed to http://localhost to to test your php code.

Link to comment
Share on other sites

Is the script saved with a .php extension?

 

If you save as htm or html the server needs to be configured to parse php.

 

No it was a .html extension. When i change it to .php extension and run it from the apache shell prompt, i get a message from windows saying it doesn't know how to run it, and plz select a program to recognise how to run it.

 

>I would suggest setting up a free hosting account using freehostia or something

That feels like cheating. All the guides say you can do it from your own machine as localhost, and several youtube tutorials do it from their own machine as the localhost too.

Edited by meemoe_uk
Link to comment
Share on other sites

It sounds like you maybe loading your .php files directly into your web browser (ie the url address starts with file://C:/User/xxx....) This is the incorrect way for testing your php code.

 

All your web site files needs to be saved in XAMPP's htdocs folder (eg C:\XAMPP\htdocs). You then proceed to http://localhost to to test your php code.

You're right, i was loading them straight into firefox.

Ok, so now I've moved my php programs into the C:\xampp\htdocs folder. Then i went to http://localhost. But i didn't see any ' run php script ' button or prompt. Strikes me as odd, because that xampp page seems to have a lot of functionality, why did they leave out a 'run php script' function?

 

so I just drag dropped my php code file windows icon into the browser ontop of the xampp page, and got the same blank page result. Still isn't working :/

Edited by meemoe_uk
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.